Advertisement
Advanced JavaScript, DOM & Events

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

Short 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.

Save JavaScript mock interview
Advertisement
AModel 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().
Likely follow-ups
  • Can you stop propagation during the capturing phase to prevent a click reaching its target at all?
Related topics