Trillium
09 Apr 2010, 04:08 PM
What is the best way to write code that binds functions to events on certain elements, when IE doesn't support the addEventListener() method? Is it even worth it to use that method, or is there a better way to code such things?
*****************
Edit
*****************
Okay, I've been playing around with the code a bit, and instead of using:
object.addEventListener('click',function(e){
alert("You clicked me!");
},false);
You can just do:
object.onclick = function(e){
alert("You clicked me!");
}
And that seems to achieve the same effect, but without the incompatibilities, and without as much code too.
So why exactly would one use addEventListener() then? (I am by no means a Javascript expert, so I am open to being educated :) )
************
Further Edit
************
In case anyone is wondering, IE uses attachEvent() instead of addEventListener()
*****************
Edit
*****************
Okay, I've been playing around with the code a bit, and instead of using:
object.addEventListener('click',function(e){
alert("You clicked me!");
},false);
You can just do:
object.onclick = function(e){
alert("You clicked me!");
}
And that seems to achieve the same effect, but without the incompatibilities, and without as much code too.
So why exactly would one use addEventListener() then? (I am by no means a Javascript expert, so I am open to being educated :) )
************
Further Edit
************
In case anyone is wondering, IE uses attachEvent() instead of addEventListener()