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
  • 15,636
  • 10
  • 72
  • 102
trrrrrrm
  • 10,718
  • 23
  • 82
  • 129

3 Answers3

26

This is what the mouseleave event is for.

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

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

jimyi
  • 29,883
  • 3
  • 37
  • 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,326
  • 4
  • 26
  • 41
nikjohn
  • 17,954
  • 13
  • 49
  • 82
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
  • 18,451
  • 5
  • 62
  • 83