The relatedTarget property of the jQuery Event Object is a normalization of the various methods used to obtain the element the mouse moves from when a mouseover or to when a mouseout event takes place. In your function this refers to the element itself (the one the event function was assigned to). These are both normal elements (not jQuery $ type arrays). I simply 'walk up the DOM tree' to see if the element is either the relatedTarget (in the case of a bubbling onmouseout event contained within it), or the parent of the relatedTarget (in the case of moving over a contained element triggering the parent's onmouseout event. I'm not sure which or if both were causing the problem, but it doesn't matter - both bases are covered.
I did a little experimenting, and it appears that both are involved. And I'm not sure if this will make it any clearer, but a jQuery shorthand method of doing the same thing would be:
Code:
$('div.accordionContent').mouseout(function(e) {
if($.inArray(e.relatedTarget, $(this).contents().andSelf()) > -1){
return;
}
$("div.accordionContent").slideUp('normal');
});
Or, even more concise:
Code:
$('div.accordionContent').mouseout(function(e) {
if($.inArray(e.relatedTarget, $(this).contents().andSelf()) < 0){
$("div.accordionContent").slideUp('normal');
}
});
Bookmarks