DOM & Events

DOM Event Propagation (Capture, Target, Bubble)

Three-phase DOM event traversal from window to target and back, enabling single-listener delegation on common ancestors.

About this page
READ
2 min
Interactive Simulator

DOM Click Propagation Lifecycle

Trace the event path from window down to <button> and back up.

window
ul (delegator)
button (target)
Step 1 / 4: 1. Hit-Testing

The engine identifies <button> as event.target at the pointer coordinates.

Internal State / Memory
eventPhase
HIT_TEST
target
<button>
currentTarget
null
DOM Click Propagation Lifecycle

Under the Hood#

  1. Hit-Testing: The engine identifies the deepest element under the pointer (event.target).
  2. Capture Phase: Walks window -> document -> html -> ... -> parent, invoking listeners registered with { capture: true }.
  3. Target & Bubble Phases: Invokes listeners on target, then walks back up to window (unless bubbles: false, such as focus, blur, or scroll).
  4. Microtask Checkpoint: Between two distinct listeners triggered by a real UI event, the Event Loop drains pending microtasks.
JS
// 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 / wheel listeners: Without { passive: true }, the Compositor Thread waits on the main thread before scrolling in case preventDefault() is called.

Where this connects

Prerequisites

Next & related

Seen in Architecture Autopsies

Mechanical Comparisons