Long long ago before the invention of social media, when browsers were nothing alike and "web designer" was your job title, I wrote a tutorial on browser event handling which included a small snippet of JavaScript code encapsulating the various implementations in a single function I named addEvent
.
I didn't know this at the time, but this naïve scrap of JS would become the most-copied-and-pasted code I would ever write. When I was hired at Amazon in 2003, I had some heart palpitations upon finding addEvent
strewn throughout the codebase. Today it's been mostly replaced, made redundant not so much by the broad adoption of the web standard addEventListener
but by the arrival of jQuery. I still found a few references as recently as 2018, and I half-regret that I didn't file a ticket to remove it, lol.
addEvent
caught the attention of web standards expert and devotee Peter-Paul Koch, aka PPK, who wrote what I consider my true crowning achievement, an extensive "considered harmful" treatise criticizing addEvent
. And he was, and still is, correct!
Nineteen years later you can still read PPK's original article at the same URL. But I've migrated and redesigned this website many, many times, eventually breaking all links to my JavaScript writing. Cool URIs don't change, but that's my secret, Captain -- my links have never been cool.
Until today, when I put my addEvent article back online at its original URL! Tidied up with some modern syntax highlighting and everything!
Crossbrowser DOM Scripting: Event Handlers | Scott Andrew
Gnarled JavaScript warlock, musician, cartoonist, dilettante.
Scott Andrew
It's very strange to look back on this after 23 years. The tone is very conciliatory ("let's not be too hard on Microsoft, I'm sure they're trying very hard!"), and the targeted browsers -- Netscape 6 and Internet Explorer 5 -- are so long gone I don't think anyone thinks of them.
Also: the case logic ends with an alert()
? What? Not console.log()
? Oh, hang on, developer consoles weren't a thing until 2006, and then you had to install Firebug!
We would get MySpace, Ajax, and YouTube several years before we had any in-browser debugging tools.
Let that sink in.