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