Can I Create Multiple Onclick Events Dynamically?
For some reason I am unable to re-enable a button and go through all of the columns I have in a table with the same button. Can I create multiple onclick events for the button? The
Solution 1:
Yes, use addEventListener
.
Instead of target.onclick=clickHandlerFunction;
, use target.addEventListener('click', clickHandlerFunction);'
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener
Note: The syntax for adding events using old Internet Explorer is different (target.attachEvent('onclick',handler)
). If you need compatibility with old browsers, you can use both syntaxes, use jQuery's click
or on
functions or gator.js.
Post a Comment for "Can I Create Multiple Onclick Events Dynamically?"