Chapter 11

Using Events in JavaScript

In This Chapter

arrow Finding out what’s happenin’

arrow Using event handlers to respond to events

arrow 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 ...

Get Coding with JavaScript For Dummies 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.