Posted By

Corhol on 09/04/06


Tagged

javascript events listener


Versions (?)

addEvent() by John Resig


 / Published in: JavaScript
 

  1. // addEvent() by John Resig
  2. // http://ejohn.org/projects/flexible-javascript-events/
  3. function addEvent ( obj, type, fn ) {
  4. if ( obj.addEventListener ) {
  5. obj.addEventListener ( type, fn, false );
  6. } else if ( obj.attachEvent ) {
  7. obj["e"+type+fn] = fn;
  8. obj[type+fn] = function ( ) { obj["e"+type+fn] ( window.event ); }
  9. obj.attachEvent ( "on"+type, obj[type+fn] );
  10. }
  11. }

Report this snippet  

You need to login to post a comment.