How does DOM event propagation work?
Explain capture, target, bubble, composed paths, and delegation—including where propagation can be stopped.
Click a button inside a card and both the button and the card may react. That is not necessarily two click events being fired. One event travels through a path of DOM elements, giving ancestors and descendants a chance to handle it. Understanding that path explains bubbling, capturing and event delegation.
Click a button inside a card and both the button and the card may react. That is not necessarily two click events being fired. One event travels through a path of DOM elements, giving ancestors and descendants a chance to handle it. Understanding that path explains bubbling, capturing and event delegation.
The quick version
An event travels through a propagation path: capture ancestors, reach the target, then bubble through ancestors when the event bubbles. Listeners can be registered for capture or bubble; not every event bubbles or is composed.
Build the mental model
event.target is the originating target (subject to shadow-DOM retargeting); event.currentTarget is the node whose listener is executing. stopPropagation stops further traversal, while preventDefault cancels a cancelable default action.
See it in code
list.addEventListener('click', (event) => {
const button = event.target.closest('button[data-action]');
if (!button || !list.contains(button)) return;
handleAction(button.dataset.action);
});
Where it gets tricky
Delegation must account for nested interactive elements: event.target may be an icon or span inside the intended button, so resolve the nearest actionable ancestor and verify it belongs to the delegated container. Shadow DOM introduces retargeting; use composedPath() when the actual propagation path is relevant. Some events, such as focus, do not bubble in the same way as focusin.
A common misunderstanding
Stopping propagation does not cancel a link’s default navigation; preventing default does not stop propagation.
What this changes in an application
Delegation reduces listener count for dynamic lists, but requires careful target validation and keyboard semantics.
Questions worth exploring next
- What changes with
stopImmediatePropagation? - How do shadow roots affect
composedPath()?
References and next steps
- Event bubbling and capture — primary or authoritative documentation for the underlying behavior.
- MDN Web Docs — use the relevant API reference for adjacent browser details.