I have this HTML. I want to attach mouseover and mouseleave events ONLY to the .parent
element, but for some reason they also get attached to the children elements and I get weird behaviour.
<div class="parent">
<div class="child-1"></div>
<div class="child-2"></div>
</div>
Here's how I do it
const parent = document.getElementsByClassName('parent')[0]
parent.addEventListener('mouseover', eventHandler)
parent.addEventListener('mouseleave', eventHandler)
Whats going on and how to prevent it?