Chapter 11. Browser Events

To add actual useful functionality to a web page, we need to do more than inspecting and modifying the document—we must be able to detect the user’s actions and respond to them. This is done by handling events, which are the subject of this chapter.

Event Handlers

Key presses, scrolling, mouse clicks, and even mouse motion are all turned into events by your browser, and we can write code to handle them. For example, in Chapter 9, we set the onclick property of a button to do some-thing when that button was clicked. That was an example of a simple event handler.

The way browser events work is, fundamentally, very simple. It is possible to register handlers for specific event types on specific DOM nodes. Whenever an event ...

Get Eloquent JavaScript now with O’Reilly online learning.

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