/ Published in: JavaScript
Cross-browser implementation of element.addEventListener(). Simple, straightforward, and functional.
Useage:
addListener(window, 'load', myFunction);
Useage:
addListener(window, 'load', myFunction);
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Cross-browser implementation of element.addEventListener() function addListener(element, type, expression, bubbling) { bubbling = bubbling || false; if(window.addEventListener) { // Standard element.addEventListener(type, expression, bubbling); return true; } else if(window.attachEvent) { // IE element.attachEvent('on' + type, expression); return true; } else return false; }