Confusion with jQuery mouseout event
Asked Answered
U

3

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

Unlicensed answered 4/4, 2010 at 17:42 Comment(1)
Possible duplicate: #351139Exurbanite
A
26

This is what the mouseleave event is for.

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

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

Amphidiploid answered 4/4, 2010 at 17:48 Comment(0)
J
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!

Jarad answered 19/2, 2014 at 11:24 Comment(0)
G
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.

Grantley answered 4/4, 2010 at 18:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.