16

My HTML:

<div id="parent">
    <div id="child">cx</div>
</div>

When I use jQuery

$('#parent').mouseout(function(){
    //something here
});

I wonder why when my mouse enter the child div the function fires. I'm still inside parent div. I want that mouseout function to fire only when I leave the parent div not when I'm on any child div.

http://jsbin.com/esiju/ << example

Cheers

informatik01
  • 16,038
  • 10
  • 74
  • 104
trrrrrrm
  • 11,362
  • 25
  • 85
  • 130

3 Answers3

26

This is what the mouseleave event is for.

$('#parent').mouseleave(function(){
//something here
});

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

jimyi
  • 30,733
  • 3
  • 38
  • 34
1

.mouseleave works perfectly here:

$("#parent").mouseleave(function(){
    //Enter stuff that should happen when mouse leaves 
    //the boundaries of the parent element
    // NOT including the children
});

.mouseout fires on mousing over child elements!

dstronczak
  • 2,406
  • 4
  • 28
  • 41
nikjohn
  • 20,026
  • 14
  • 50
  • 86
0

There seems to be a bit of difference between the mouseout and mouseover events. jimyi has the correct solution for your problem, I just wanted to include some additional links for completeness.

Roman
  • 19,581
  • 6
  • 68
  • 84