Last active
January 1, 2016 23:59
-
-
Save LiamChapman/8220065 to your computer and use it in GitHub Desktop.
Shorthand cross-browser code for binding events to elements e.g. document.getElementById('#foo').on('click', function () { alert('hi!'); });
This file contains hidden or 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
| Element.prototype.on = function (evnt, func) { | |
| if (this.addEventListener) // W3C DOM | |
| this.addEventListener(evnt, func, false); | |
| else if (this.attachEvent) { // IE DOM | |
| var r = this.attachEvent("on"+evnt, func); | |
| return r; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment