Skip to content

Instantly share code, notes, and snippets.

@samarpanda
Last active August 29, 2015 13:56
Show Gist options
  • Save samarpanda/9097997 to your computer and use it in GitHub Desktop.
Save samarpanda/9097997 to your computer and use it in GitHub Desktop.
Flexible javascript events By John Resig http://ejohn.org/projects/flexible-javascript-events/
// Attach event
function addEvent(obj, type, fn){
if( obj.attachEvent ){
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn](window.event);};
obj.attachment( 'on'+type, obj[type+fn]);
}else
obj.addEventListener(type, fn, false);
}
// Remove event
function removeEvent(obj, type, fn){
if(obj.detachEvent){
obj.detachEvent('on'+type, obj[type+fn]);
obj[type+fn] = null;
}else
obj.removeEventListener(type, fb, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment