I have HTML that looks like this:
<div id="parent">
<div class="child">
Child 1
</div>
<div class="child">
Child 2
</div>
<div class="child">
Child 3
</div>
</div>
I attach mouseenter and mouseout events like so:
$("*").on("mouseenter", function() {
$(this).addClass("mouse_over");
});
$("*").on("mouseout", function() {
$(this).removeClass("mouse_over");
});
Now, imagine the following mouse sequence of events:
- I move the mouse into the parent div. As expected the mouseenter event fires and the mouse_over class is put on the parent.
- I move into one of the children. The mouseout event fires for the parent, and the mouseenter event fires for the child. Good.
- I move the mouse back into the parent. The mouseenter DOES NOT fire here.
The third step is the issue here. I want the mouse_over class to be put back on the parent when reentering the parent from its child element.
I think I understand why this is happening, as technically my mouse is in the parent the whole time so firing the mouseenter event does not make sense.
Here's a fiddle better illustrating what I'm trying to do:
https://jsfiddle.net/tg1wg1xx/
If you hover into the parent and children elements, you'll notice on your way out the pattern overlay is not placed on the parent.
So how can I ensure that the overlay is always placed on whatever element I am currently hovering over?