Posted By

iroybot on 07/11/10


Tagged

javascript js addevent


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

iroybot
nerdfiles
dipser


addEvent


 / Published in: JavaScript
 

  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.