liveBook · Manning

Event delegation

Event delegation is an event-handling technique in which an ancestor handles events from descendant elements through event propagation.

How 2 Manning books explain it

Secrets of the JavaScript Ninja, Second Edition

An event-handling pattern in which a parent or ancestor element handles events for descendant elements by relying on propagation.

How it is used
Replaces repeated click handlers on table cells with one handler on their ancestor table.
How deep it goes
Explains bubbling, ancestor placement, and the difference between event.target and this through DOM click examples.
Examples
Contrasts per-cell listeners with a table handler that colors clicked cells, and uses nested elements to show propagation.
What you can do after
Apply it via addEventListener to handle descendant clicks at an ancestor while distinguishing the clicked target from the handler element.

Read how Secrets of the JavaScript Ninja, Second Edition explains event delegation →

Vanilla Web

An event-handling technique that registers a listener on an ancestor and identifies relevant descendant interactions from the event.

How it is used
Handles repeated controls through a container listener to reduce listener overhead.
How deep it goes
Explains bubbling and target/currentTarget with a logging example, but stops short of a complete child-interaction filter.
Examples
Uses a customer list with 1,000 items and a smaller <ul> example that logs click targets.
What you can do after
Apply it via addEventListener to handle repeated controls with one container listener while checking the event target.

Read how Vanilla Web explains event delegation →

Also covered in

What to know first

Related concepts

Questions about event delegation

What is event delegation?

Event delegation is an event-handling technique in which an ancestor handles events from descendant elements through event propagation.

Which Manning books explain event delegation?

Secrets of the JavaScript Ninja, Second Edition and Vanilla Web.

What should I know before learning event delegation?

Manning books that teach event delegation usually introduce Document Object Model, event and performance first.

What is the difference between event delegation and non-bubbling event?

Event delegation is an event-handling technique in which an ancestor handles events from descendant elements through event propagation. A non-bubbling event is a DOM event whose propagation does not continue from its target to ancestor elements.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.