composedPath().

 


document.body.addEventListener("click", (eventObject) => { let tabulation = "".padEnd(eventObject.composedPath().length, "▶️"); eventObject.composedPath().forEach((elt) => { document.body.insertAdjacentHTML( "beforeEnd", `<p>Clicked on: ${tabulation} ${elt.nodeName ? elt.nodeName : "Window"}` ); tabulation = tabulation.slice(0, -1); }); });


See the Pen Untitled by dupont (@dupontcodepen) on CodePen.