Learning object 41 of 100
Event propagation visualizer
Click nested boxes and watch an event travel down in the capture phase, reach its target and bubble back up, with stopPropagation available at any step.
Loading…
What it shows
An event starts at the window, travels down through each ancestor (capture phase), reaches the target, and then travels back up (bubble phase). Listeners added with { capture: true } run on the way down; ordinary listeners run on the way up. stopPropagation stops the journey; it does not cancel the default action. Some events, such as focus, do not bubble.
Guided experiment
- In Phases, click the innermost box in the preview. Count the capture and bubble lines.
- In stopPropagation, click the inner button and then the outer box.
- In Not every event bubbles, compare focus with focusin.
Predict
A click on a button inside a div: which ordinary (bubble) listener runs first?
Related
Lessons: Lesson 58: Event bubbling and capturing
Projects: Project 9: Shopping Cart Price Calculator
Source: web/assets/js/objects/object-041.js in the companion repository.