Chapter 11

Using Events in JavaScript

IN THIS CHAPTER

Bullet Finding out what’s happenin’

Bullet Using event handlers to respond to events

Bullet Knowing the types of event handlers

“And now, the sequence of events in no particular order:”

— DAN RATHER

Web pages are much more than just static displays of text and graphics. JavaScript gives web pages interactivity and the ability to perform useful work. An important part of JavaScript’s ability to perform useful functions in the browser is its ability to respond to events.

Knowing Your Events

Events are the things that happen within the browser (such as a page loading) and things the user does (such as clicking, pressing keys on the keyboard, moving the mouse, and so on). Events happen all the time in the browser.

The HTML DOM gives JavaScript the ability to identify and respond to events in a web browser. Events can be divided into groups according to what HTML elements or browser objects they apply to. Table 11-1 lists events that are supported by every HTML element.

TABLE 11-1 Events Supported by All HTML Elements

Event

Occurs When …

abort

The loading of a file is aborted.

change

An elements value has changed since losing and regaining ...

Get Coding All-in-One For Dummies, 2nd 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.