Skip to content

Instantly share code, notes, and snippets.

@scottandrewlepera
Created May 29, 2024 18:06
Show Gist options
  • Save scottandrewlepera/138b66abf8ea8f2dffdfee892c901ee3 to your computer and use it in GitHub Desktop.
Save scottandrewlepera/138b66abf8ea8f2dffdfee892c901ee3 to your computer and use it in GitHub Desktop.
The Original AddEvent
/*
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