Example 1 — Log Path Tags
Map composedPath() to simple labels for debugging.
document.addEventListener("click", (e) => {
const labels = e.composedPath().map((n) => {
if (n === window) return "window";
if (n === document) return "document";
if (n instanceof Element) {
return n.id ? "#" + n.id : n.tagName.toLowerCase();
}
return n.constructor.name;
});
console.log(labels.join(" → "));
}); How It Works
- Listen for click. Any click on the page reaches this handler if it bubbles.
- Call composedPath. Get the full
EventTargetarray. - Map labels. Turn nodes into short names for the console.
- Read deepest first. Index
0is usually the click origin.

