Chapter 7. Events

As an event-driven programming language, JavaScript does very little on its own; instead, it waits for the user to do something, and then reacts by executing a bit of script.

In order to find out what’s going on in the HTML page, the DOM supports events. Every time the user takes an action—for instance, she clicks on a link, submits a form, loads a new page, changes the value of a form field, or presses a key—an event fires.

You can add event handlers to any elements. Event handlers are functions that are automatically executed when the event takes place on that element. If the script is well thought out, the page responds to user actions and interactivity is born.

All example scripts in this book are event-driven: they kick ...

Get ppk on 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.