Back to results for “Design Patterns in JavaScript”
JavaScript › DOM & Events

What's the difference between the capturing and bubbling phases of event propagation?

Advanced

Answer

Events actually travel in three phases: capturing (top-down, from window to the target), target phase, then bubbling (bottom-up, target back to window). Listeners default to the bubbling phase; pass { capture: true } to react during the capturing phase instead.
el.addEventListener('click', handler, { capture: true }); // fires during capture (top-down)
el.addEventListener('click', handler); // fires during bubble (bottom-up), the default
Real-world example Intercepting a click at a top-level container BEFORE it reaches a deeply nested element that might call stopPropagation().

Common follow-ups: Can you stop propagation during the capturing phase to prevent a click reaching its target at all?