A click on a nested element can trigger listeners on its ancestors. DOM events travel through three phases: capture moves down the tree, the target phase reaches the clicked element, and the bubble phase carries the event back up through its ancestors toward the document and window. Listeners use the bubble phase by default; request capture explicitly when you need the downward path. section 6.2.13
const header = document.querySelector("header");
const p = document.querySelector("p");
// Capture phase: fires top-down, from document to the target
document.addEventListener("click", () => #1
console.log("1 document capture"), { capture: true });
document.body.addEventListener("click", () =>
console.log("2 body capture"), { capture: true });
header.addEventListener("click", () =>
console.log("3 header capture"), { capture: true });
p.addEventListener("click", () =>
console.log("4 p capture"), { capture: true });
// Bubble phase: fires bottom-up, from the target to document
p.addEventListener("click", () => #2
console.log("5 p bubble"));
header.addEventListener("click", () =>
console.log("6 header bubble"));
document.body.addEventListener("click", () =>
console.log("7 body bubble"));
document.addEventListener("click", () =>
console.log("8 document bubble"));
Compare the logged order for capture listeners with the bottom-up order for bubble listeners when the paragraph is clicked. section 6.2.13
A list-level click listener
Attach one click listener to a list and click a list item. The event’s target identifies the clicked element, while currentTarget identifies the list running the listener. An ancestor listener can therefore react without being attached to each item. section 6.2.13
Use addEventListener when multiple handlers or listener options are needed. CustomEvent can also be dispatched with bubbles: true so an ancestor listener can receive it. section 6.2.13

