Let's suppose there is an <img>
element that has some onclick event handler. For example onclick it does alert("OldEventHandler")
.
I would like to add my event handler there, before the existing one. For example my event handler function does alert("NewEventHandler")
.
So on click I would like to see "NewEventHandler" popup, and then "OldEventHandler" popup.
This needs to be implemented in pure JavaScript; no jQuery Please.
You can save the original handler, then call it after yours is done:
var oldHandler = myElement.onclick;
myElement.onclick = function() {
// do your stuff here
...
// then call the original
oldHandler.apply(this, arguments);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With