Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

addEventListener not working in IE8

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.

like image 865
ravi404 Avatar asked Mar 19 '12 12:03

ravi404


Video Answer


1 Answers

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.

like image 159
Sudhir Bastakoti Avatar answered Sep 18 '22 09:09

Sudhir Bastakoti