8. Event Handling

Handling events is one of the fundamental uses of JavaScript. Loading a Web page, moving the cursor, entering text into a textarea, submitting a form: these are all events that occur within the browser to which JavaScript can respond. Out of necessity, Chapter 2, JavaScript in Action, introduced the very basics of event handling, and it also presented two events, used in most of the book’s examples thus far. In this chapter, you’ll learn everything you need to know to handle the myriad of events in JavaScript.

The Premise of Event Handling

Chapter 2 explained that creating an event handler in JavaScript is a matter of associating an event and an object with a JavaScript function. For example:

window.onload = init;

That one line ...

Get Modern JavaScript: Develop and Design now with O’Reilly online learning.

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