When a DOM event is dispatched, the browser computes the propagation path from window down to the target and then runs listeners in three phases: 1. capture (from window down to the target's parent, for capture listeners), 2. target (on the target itself), and 3. bubble (from the target's parent back up to window, for non-capture listeners, only if the event bubbles). event.eventPhase reports which phase is running (1, 2, 3; 0 when not dispatching).
<body>
<section id="card">
<button id="buy">Buy</button>
</section>
</body>
const log = (label) => (e) => console.log(label, e.eventPhase);
window.addEventListener('click', log('window capture'), true);
card.addEventListener('click', log('card capture'), true);
buy.addEventListener('click', log('buy capture'), true);
buy.addEventListener('click', log('buy bubble'));
card.addEventListener('click', log('card bubble'));
window.addEventListener('click', log('window bubble'));
Clicking the button logs:
window capture 1
card capture 1
buy capture 2 ← target phase
buy bubble 2 ← target phase
card bubble 3
window bubble 3
At the target, the spec runs capture listeners first, then non-capture ones (browsers aligned with this around 2021; before that, the target ran listeners purely in registration order).
Capture: opt in with { capture: true }. Useful when an ancestor needs to see or intercept the event before descendants, and to observe events that don't bubble (focus, blur, mouseenter, scroll on elements).
Target: listeners on event.target itself. event.currentTarget === event.target here.
Bubble: the default phase for listeners and the basis of event delegation. Only happens if event.bubbles is true. Most UI events bubble (click, input, keydown, submit, focusin); some don't (focus, blur, load, mouseenter/mouseleave).
card.addEventListener('click', (e) => {
e.stopPropagation(); // later nodes in the path won't get it
// e.stopImmediatePropagation(); // also skip remaining listeners on this node
}, true);
Stopping during capture means the target never receives the event. Neither method affects the browser's default action. That's preventDefault().
event.target. event.composedPath() returns the full path (open shadow roots only), and composed: false events (many custom events by default) stop at the shadow root.bubbles: true.onClick / onClickCapture), so native listeners on inner elements run before React's bubble handlers.stopPropagation in a bubble handler to block a capture listener on an ancestor; the capture listener has already run.stopPropagation, which silently breaks analytics, outside-click logic and delegated handlers elsewhere.removeEventListener must match the capture flag.eventPhase, and which events don't bubble.target vs currentTarget, and how phases enable delegation and outside-click detection.composedPath() and the React root listener model as senior-level details.Spotted a mistake or a rights concern? Report an issue