You are previewing Eloquent JavaScript.

Eloquent JavaScript

Cover of Eloquent JavaScript by Marijn Haverbeke Published by No Starch Press

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

The best content for your career. Discover unlimited learning on demand for around $1/day.