Created
May 29, 2024 18:06
-
-
Save scottandrewlepera/138b66abf8ea8f2dffdfee892c901ee3 to your computer and use it in GitHub Desktop.
The Original AddEvent
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
/* | |
Original tutorial URL from 2001 | |
"Crossbrowser DOM Scripting: Event Handlers" | |
https://scottandrew.com/weblog/articles/cbs-events | |
Archive.org link: | |
https://web.archive.org/web/20051124085135/https://scottandrew.com/weblog/articles/cbs-events | |
"AddEvent considered harmful" | |
https://www.quirksmode.org/blog/archives/2005/08/addevent_consid.html | |
*/ | |
function addEvent(obj, evType, fn, useCapture){ | |
if (obj.addEventListener){ | |
obj.addEventListener(evType, fn, useCapture); | |
return true; | |
} else if (obj.attachEvent){ | |
var r = obj.attachEvent("on"+evType, fn); | |
return r; | |
} else { | |
alert("Handler could not be attached"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment