In my window event, if the pointer clicks on the parent or its child/descendant, it should do something.
The problem is the event can't access the parent's child and grand child. The condition is stored in the targetIsInsideParent
variable.
HTML
<div class="parent">
Parent
<div class="child">
Child
<div class="grandchild">
GrandChild
</div>
</div>
</div>
JS
const parent = document.querySelector('.parent');
window.addEventListener('click', e => {
const targetIsParent = e.target === parent;
const targetIsInsideParent = e.target === parent.children; // !!!!
if(targetIsParent || targetIsInsideParent) {
console.log('Good');
}
})