Triggering Events

So far all the JavaScript we've seen is triggered when a web page loads into a browser. But JavaScript can also be event driven.

Event-driven JavaScript waits for your visitor to take a particular action, such as mousing over an image, before it reacts. The key to coding event-driven JavaScript is to know the names of events and how to use them.

Event Types

With JavaScript's help, different parts of your web page can detect different events. For example, a pull-down menu can know when it has changed (see Chapter 7); a window when it has closed (see Chapter 5); and a link when a visitor has clicked on it. In this chapter I'll focus on link events.

A link can detect many kinds of events, all of which involve interactions with the mouse. ...

Get The Book of JavaScript, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.