Skip to content

Instantly share code, notes, and snippets.

@jasdeepkhalsa
Created December 11, 2012 11:34
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 jasdeepkhalsa/4257932 to your computer and use it in GitHub Desktop.
Save jasdeepkhalsa/4257932 to your computer and use it in GitHub Desktop.
John Resig's addEvent Cross Browser Method
function addEvent( obj, type, fn )
{
if (obj.addEventListener)
obj.addEventListener( type, fn, false );
else 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] );
}
}
function removeEvent( obj, type, fn )
{
if (obj.removeEventListener)
obj.removeEventListener( type, fn, false );
else if (obj.detachEvent)
{
obj.detachEvent( "on"+type, obj[type+fn] );
obj[type+fn] = null;
obj["e"+type+fn] = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment