Event Capturing
Event capturing is the first phase of DOM event propagation, during which an event travels from the document root downward through each ancestor element to the target, giving outer elements the opportunity to intercept events before they reach the target.
Event capturing is the first phase of DOM event propagation, during which an event travels from the document root downward through each ancestor element to the target, giving outer elements the opportunity to intercept events before they reach the target.
The full DOM event propagation model has three phases: capture, target, and bubble. Capturing runs first, always. When an event is dispatched, the browser starts at window, then descends through each ancestor: document, , , and through the DOM tree to the event's target element. Listeners registered with addEventListener('click', handler, true) or addEventListener('click', handler, { capture: true }) participate in this downward phase. Standard listeners (without the capture flag) only run during the target and bubbling phases.
Event capturing is less commonly used than Event Bubbling, but it has specific use cases where it is the correct tool. If you need to intercept an event before it reaches a child element — for example, to prevent a modal's inner content from receiving scroll events that would otherwise propagate to an outer scroller — a capture-phase listener on the outer element fires before any bubble-phase listener on the child. It is also used in accessibility toolkits that need to monitor all events on a page without being blocked by stopPropagation calls in application code.
Calling event.stopPropagation() inside a capture-phase listener halts the event entirely — it neither reaches the target nor enters the bubble phase. This makes capture-phase listeners a powerful but sharp tool; misuse can silently swallow events that other parts of the application depend on.
The full sequence for a click on a inside a window capture → document capture → body capture → div capture → button capture → button target → div bubble → body bubble → document bubble → window bubble. Understanding this complete sequence is essential for debugging unexpected event behavior.Frequently asked questions