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

Get Eloquent JavaScript 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.