How to call multiple JavaScript functions in onclick event? How to call multiple JavaScript functions in onclick event? javascript javascript

How to call multiple JavaScript functions in onclick event?


onclick="doSomething();doSomethingElse();"

But really, you're better off not using onclick at all and attaching the event handler to the DOM node through your Javascript code. This is known as unobtrusive javascript.


A link with 1 function defined

<a href="#" onclick="someFunc()">Click me To fire some functions</a>

Firing multiple functions from someFunc()

function someFunc() {    showAlert();    validate();    anotherFunction();    YetAnotherFunction();}


This is the code required if you're using only JavaScript and not jQuery

var el = document.getElementById("id");el.addEventListener("click", function(){alert("click1 triggered")}, false);el.addEventListener("click", function(){alert("click2 triggered")}, false);