Posted By

oronm on 09/05/06


Tagged

original addevent


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vanne
vali29


addEvent


 / Published in: JavaScript
 

URL: http://www.dustindiaz.com/top-ten-javascript/

Surely a staple to event attachment! Regardless to what version you use written by whatever developer, it does what it says it does. And of course as you might of known, I’ve put together quite a handy version myself recently of addEvent() with some help from the contest winner and Mark Wubben along with a few minor syntax adjustments. But just to be fair to Scott Andrew, here is the original that started it all.

  1. function addEvent(elm, evType, fn, useCapture) {
  2. if (elm.addEventListener) {
  3. elm.addEventListener(evType, fn, useCapture);
  4. return true;
  5. }
  6. else if (elm.attachEvent) {
  7. var r = elm.attachEvent('on' + evType, fn);
  8. return r;
  9. }
  10. else {
  11. elm['on' + evType] = fn;
  12. }
  13. }

Report this snippet  

You need to login to post a comment.