How to make sure that the element clicked has got parent or grandparent with certain class?
document.getElementById("app").innerHTML = `
<div class="dynamic">
<div class="level1">
<h2 class="title">I am a title</h2>
<div class="level2">
<h3 class="subtitle">I am a subtitle</h3>
<div class="level3">
<p class="hello">Hello, I am a paragraph</p>
<p class="bye">Bye</p>
</div>
</div>
</div>
</div>
`;
document.addEventListener("click", function(e) {
// pseudocode mode start
// if (clicked e.target is or has got a parent(or grandparent or grandgrandparent) with class "dynamic")
// (so clicking enywhere in dynamic div (both the paragraphs, the title and subtitle will result in action))
// pseudocode mode stop
});