Skip to content

Instantly share code, notes, and snippets.

@rowej83
Last active December 8, 2015 18:24
Show Gist options
  • Save rowej83/5a0f4c0f24cc3efc05a2 to your computer and use it in GitHub Desktop.
Save rowej83/5a0f4c0f24cc3efc05a2 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 );
}
//http://ejohn.org/projects/flexible-javascript-events
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment