Posted By

rhlowe on 07/02/07


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

noah
alyssonweb


Cross Browser Add Event Listener


 / Published in: JavaScript
 

Snatched this from another post and fixed something I found was not working.

  1. // Cross-browser implementation of element.addEventListener()
  2.  
  3. function listen(evnt, elem, func) {
  4. if (elem.addEventListener) // W3C DOM
  5. elem.addEventListener(evnt,func,false);
  6. else if (elem.attachEvent) { // IE DOM
  7. var r = elem.attachEvent("on"+evnt, func);
  8. return r;
  9. }
  10. else window.alert('I\'m sorry Dave, I\'m afraid I can\'t do that.');
  11. }
  12.  
  13. // Use: listen("event name", elem, func);

Report this snippet  

You need to login to post a comment.