Adding an Event Listener

Browsers are busy pieces of software. Every tap, click, scroll, and keystroke is noticed by the browser. Each of these is an event that the browser may respond to. To make websites more dynamic and interactive, you can trigger your own code when one of these events occurs. In this section, you will add event listeners to each of your thumbnails.

An event listener is an object that, as the name suggests, “listens” for a particular event, such as a mouse click. When its assigned event occurs, the event listener triggers a function call in response to the event.

(Mouse events, like clicks and double-clicks, and keyboard events like keypresses are among the most common event types. For a complete listing of ...

Get Front-End Web Development: The Big Nerd Ranch Guide 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.