Skip to content

Instantly share code, notes, and snippets.

@OscarGodson
Created April 12, 2013 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OscarGodson/e2b8b917e947765b543f to your computer and use it in GitHub Desktop.
Save OscarGodson/e2b8b917e947765b543f to your computer and use it in GitHub Desktop.
function addEvent( obj, type, fn ) {
if ( obj.attachEvent ) {
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
obj.attachEvent( 'on'+type, obj[type+fn] );
} else
obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
if ( obj.detachEvent ) {
obj.detachEvent( 'on'+type, obj[type+fn] );
obj[type+fn] = null;
} else
obj.removeEventListener( type, fn, false );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment