DOM Event Propagation (Capture, Target, Bubble)
Every DOM event traverses the tree downward (Capture), reaches the originating element (Target), and walks back up to window (Bubble). Delegation attaches a single listener on a shared ancestor and identifies targets via event.target.closest(...).
DOM Click Propagation Lifecycle
Trace the event path from window down to <button> and back up.
The engine identifies <button> as event.target at the pointer coordinates.
- eventPhase
- HIT_TEST
- target
- <button>
- currentTarget
- null
Under the Hood
- Hit-Testing: The engine identifies the deepest element under the pointer (
event.target). - Capture Phase: Walks
window -> document -> html -> ... -> parent, invoking listeners registered with{ capture: true }. - Target & Bubble Phases: Invokes listeners on
target, then walks back up towindow(unlessbubbles: false, such asfocus,blur, orscroll). - Microtask Checkpoint: Between two distinct listeners triggered by a real UI event, the Event Loop drains pending microtasks.
// Single delegated listener handles 1,000 rows without per-row allocations
tableBody.addEventListener('click', (event) => {
const row = event.target.closest('tr[data-row-id]');
if (!row) return;
selectRow(row.dataset.rowId);
});Problem Genealogy
- 2000 (Incompatible Netscape/IE Models): Capture-only in Netscape, Bubbling-only in Internet Explorer, forcing every library to ship a bespoke event normalizer.
- 2002 (DOM Level 2 Events): Unified three-phase model (
addEventListener(type, fn, useCapture)). - 2015+ (Root Event Delegation in Frameworks): Single listener at the framework root avoiding thousands of per-node listener allocations.
Production Pitfalls
stopPropagation()breaks analytics and popovers: Halting propagation prevents global listeners (including Popover API light-dismiss or telemetry) from receiving the event.- Non-passive
touchstart/wheellisteners: Without{ passive: true }, the Compositor Thread waits on the main thread before scrolling in casepreventDefault()is called.
- When not to use bubbling delegation: Events that do not bubble (
mouseenter,mouseleave,focus,blur) requirefocusin/focusoutor Capture-phase listeners, and bulk teardown is cleaner via AbortController{ signal }options.
Connections & Logical Next Steps
- What This UnlocksAsync Clipboard API and User Activation
- What This UnlocksThe inert Attribute and Modal Focus Containment
- What This UnlocksPassive Event Listeners and Compositor Scrolling
- What This UnlocksPointer Events, touch-action, and Pointer Capture
- What This UnlocksShadow DOM Encapsulation and Event Retargeting
- Under the HoodEvent Loop, Macrotasks, and Microtask Queue
Transient user activation is minted by trusted input events dispatching through the DOM.
Inert subtrees suppress pointer and keyboard event dispatch during hit-testing before propagation.
Passive flags are checked during hit-testing before dispatching wheel or touch propagation.
Pointer events follow standard capture/target/bubble propagation unless redirected by setPointerCapture().
Shadow trees modify event propagation by retargeting event.target to the host at the ShadowRoot.
Each user interaction event is dispatched as a macrotask with a microtask checkpoint after every listener.
Resumability relies on a single root event-delegation listener to intercept clicks before component JS loads.
A single keydown listener on the container intercepts Arrow keys via event bubbling.
Passing an AbortSignal to addEventListener detaches groups of listeners without manual removeEventListener calls.