I came across this problem when I found the solution to my question from earlier today (if interested, find it here).
I have a simple structure of divs:
<div id="outer">
<div id="inner">
<div id="content"></div>
<div id="handle">HOVER HERE</div>
</div>
</div>
There is a mouseout event registered to outer
:
$('#outer').on('mouseout', function(event) {
if (!(event.relatedTarget.id == "outer") &&
!$(event.relatedTarget).isChildOf("outer")) {
mouseIsOverMenu = false;
menu_rollin();
}
});
(You can see the entire working example here.)
This is the simple version of a menu which has slideDown/slideUp effects.
Now here's my problem:
I totally understand that the mouseout fires on entering a child element (that's the reason for the isChildOf
check). What I don't understand is, that the event is fired when I move the mouse from content
to outer
(inner
just centers the actual content while content
is the sliding part and has the same width as inner
.) This is why I added the check if the relatedTarget is the element itself.
For my understanding, there shouldn't be any mouseout events on the child(ren). However, during good old 'alert-debugging' it turned out that the event seems to fire if the mouse goes from content
back to outer
, and of course, the isChildOf
check failed for outer
itself (which is the relatedTarget).
I read about bubbling and capturing again, but I understand it that way, that it is only relevant if more than one eventhandler for a particular event is present.
I would appreciate any explanation or resource which helps understanding the reason for this.