Created
December 11, 2012 11:34
-
-
Save jasdeepkhalsa/4257932 to your computer and use it in GitHub Desktop.
John Resig's addEvent Cross Browser Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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