Chapter 32. Event Objects

IN THIS CHAPTER

  • The "life" of an event object

  • Event support in different browser generations

  • Retrieving information from an event

Prior to version 4 browsers, user and system actions—events—were captured predominantly by event handlers defined as attributes inside HTML tags. For instance, when a user clicked a button, the clickevent triggered the onclick event handler in the tag. That handler may invoke a separate function or perform some inline JavaScript script. Even so, the events themselves were rather dumb: Either an event occurred or it didn't. Where an event occurred (that is, the screen coordinates of the pointer at the moment the mouse button was clicked) and other pertinent event tidbits (for example, whether a keyboard modifier key was pressed at the same time) were not part of the equation—until version 4 browsers, that is.

While remaining fully backward compatible with the event handler mechanism of old, version 4 browsers had the first event model that turn events into first-class objects whose properties automatically carry a lot of relevant information about the event when it occurs. These properties are fully exposed to scripts, allowing pages to respond more intelligently about what the user does with the page and its elements.

Another new aspect of version 4 event models was the notion of "event propagation." It was possible to have an event processed by an object higher up the element containment hierarchy whenever it made sense to have multiple ...

Get JavaScript® Bible, Seventh Edition 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.