beetle
12-23-2002, 04:40 PM
Anyone know of any practical/usable/compatible/whatever differences between assigning events as a property vs. using the addEventListener or attachEvent methods?
Examplevar d = document.getElementById('myDiv');
// Property assignment
d.onclick = function() { alert( this.nodeName ) }
// attachEvent method
d.attachEvent( "onclick", function() { alert( this.nodeName ) } );
// addEventListener method
d.addEventListener( "click", function() { alert( this.nodeName ) }, false );Ok, I recognize that addEventListener differs in that it allows you to toggle the capturing phase. Other than that, what sort of differences are we looking at here?
Examplevar d = document.getElementById('myDiv');
// Property assignment
d.onclick = function() { alert( this.nodeName ) }
// attachEvent method
d.attachEvent( "onclick", function() { alert( this.nodeName ) } );
// addEventListener method
d.addEventListener( "click", function() { alert( this.nodeName ) }, false );Ok, I recognize that addEventListener differs in that it allows you to toggle the capturing phase. Other than that, what sort of differences are we looking at here?