Search code examples
jqueryhoverjquery-eventsmouseout

Why does .mouseOut() fire when hovering over text inside the mouseOut target?


For example, if I do $('div#something').mouseout(function(){}); then the function will fire when I hover on text that is inside the #something div instead of when I leave the div.

I want it to fire only when I leave the div, not when I hover over text inside the div.

Why is this happening?


Solution

  • mouseout fires whenever the mouse cursor leaves an element, even if "leaving" means it is entering a child element (which the text would be - at least on some browsers).

    You may want to use "mouseleave" instead.

    http://api.jquery.com/mouseleave/