Explain the phases of DOM event propagation: capturing, target and bubbling. How do you stop propagation, and when should you avoid doing so?
Show the explanation
Model answer. When you click an element, the event travels in three phases:
- Capturing: from
windowdown through each ancestor to the target. - Target: at the element itself.
- Bubbling: back up from the target through each ancestor to
window.
Listeners run in the bubbling phase by default. Pass { capture: true } (or true) to run in the capturing phase instead.
outer.addEventListener('click', () => log('outer capture'), { capture: true });
inner.addEventListener('click', () => log('inner'));
outer.addEventListener('click', () => log('outer bubble'));
// clicking inner logs: outer capture, inner, outer bubbleevent.stopPropagation()stops the event moving to further elements.event.stopImmediatePropagation()also stops other listeners on the same element.
Avoid stopping propagation casually: analytics, dropdowns that close on outside clicks, and event delegation all rely on events bubbling. Not every event bubbles (focus, blur, mouseenter do not; focusin, focusout do).
Original UniCircle question. Last reviewed 22 Oct 2026.
