Created
April 25, 2011 06:26
-
-
Save boopathi/940232 to your computer and use it in GitHub Desktop.
cross-browser addEvent
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
Object.prototype.addEvent = function(evt, handler, useCapt) { | |
//JUST A CHECK TO HANDLE “onclick” and “click” as evt | |
if(evt.match(“^on”)) | |
evt = evt.substr(2); | |
if(this.attachEvent) | |
return this.attachEvent('on' + evt, handler); // FOR IE | |
else if(this.addEventListener) | |
return this.addEventListener(evt, handler, useCapt); // OTHERS | |
else { | |
//IF BOTH FAILS | |
this[‘on’+evt] = handler; | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment