Chapter 18. Using Early DOM Event Handlers

The HTML event handler attributes certainly work, and every browser continues to support them despite the fact that they were invented in very early versions of Netscape. However, as you may have surmised, handling events with HTML attributes can become a tedious endeavor mainly because you have to locate and add attributes to every element you want the user to interact with. Keep in mind that all those years ago, the majority of websites were primarily static, and the developers responsible for generating those websites had complete control over each page's HTML. It was also a time before the idea of separating markup (HTML) from style (CSS) and behavior (JavaScript) really gained traction.

The fourth generation of browsers, primarily Internet Explorer 4 and Netscape 4, introduced a new way of assigning event handlers by using what are now referred to as DOM Level 0 event handlers. Think of a "level" as a version; these event handlers are called DOM Level 0 event handlers because they existed before any W3C DOM standard. Yet all browsers support them. Even to this day, DOM Level 0 event handlers are widely used and are an integral part of many web applications.

Early DOM event handlers are so popular because they are supported by all browsers (something you'll appreciate in coming lessons), and you can use them in JavaScript code, effectively decoupling JavaScript from HTML.

ASSIGNING EVENT HANDLERS

DOM Level 0 event handlers are properties ...

Get JavaScript® 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.