I have created a checkbox dynamically. I have used addEventListener
to call a function on click of the checkbox, which works in Google Chrome and Firefox but doesn't work in Internet Explorer 8. This is my code:
var _checkbox = document.createElement("input"); _checkbox.addEventListener("click", setCheckedValues, false);
setCheckedValues
is my event handler.
Try:
if (_checkbox.addEventListener) { _checkbox.addEventListener("click", setCheckedValues, false); } else { _checkbox.attachEvent("onclick", setCheckedValues); }
Update:: For Internet Explorer versions prior to IE9, attachEvent method should be used to register the specified listener to the EventTarget it is called on, for others addEventListener should be used.
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