addEvent() by John Resig


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.