Tuesday, 10 September 2013

Anyway to use two .onclick event handlers from two different scripts on one button?

Anyway to use two .onclick event handlers from two different scripts on
one button?

Is it possible to use two .onclick event handlers on the same button when
the event handlers are stored in two different scripts? I know it would be
easy to just call the two functions I need into the same .onclick handler,
but I'm curious if there's a way around this.
Suppose I have
script1.js
someButton.onclick = function() {
someFunction1();
}
script2.js
someButton.onclick = function() {
someFunction2();
}
Running these scripts in the html in this order would lead to calling
someFunction2() onclick, as I assume the functionality of the button is
overwritten by script2.js.

No comments:

Post a Comment