Skip to Main Content
Professional, JavaScript® for Web Developers, Second Edition
book

Professional, JavaScript® for Web Developers, Second Edition

by Nicholas C. Zakas
January 2009
Intermediate to advanced content levelIntermediate to advanced
836 pages
21h 30m
English
Wrox
Content preview from Professional, JavaScript® for Web Developers, Second Edition

Chapter 12. Events

JavaScript's interaction with HTML is handled through events, which indicate when particular moments of interest occur in the document or browser window. Events can be subscribed to using listeners (also called handlers) that execute only when an event occurs. This model, called the observer pattern in traditional software engineering, allows a loose coupling between the behavior of a page (defined in JavaScript) and the appearance of the page (defined in HTML and CSS).

Events first appeared in Internet Explorer (IE) 3 and Netscape Navigator 3 as a way to offload some form processing from the server onto the browser. Each browser delivered similar but different APIs that continued for several generations. DOM Level 2 was the first attempt to standardize the DOM events API in a logical way. Firefox, Opera, Safari, and Chrome all have implemented the core parts of DOM Level 2 Events. IE is the only major browser that still uses a proprietary event system.

The browser event system is a complex one. Even though three of the four major browsers have implemented DOM Level 2 Events, the specification doesn't cover all event types. The Browser Object Model (BOM) also supports events and the relationship between these and the Document Object Model (DOM) events is unclear, because it is not defined by any specification. Further complicating matters is the augmentation of the DOM events API by DOM Level 3. Working with events can be relatively simple or very complex, depending ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Professional: JavaScript® for Web Developers, Third Edition

Professional: JavaScript® for Web Developers, Third Edition

Nicholas C. Zakas
JavaScript: Best Practice

JavaScript: Best Practice

James Kolce, Moritz Kroger, Ivan Curic, Samier Saeed, Jeff Mott, M. David Green, Craig Buckler

Publisher Resources

ISBN: 9780470227800Purchase book