开发者

jquery mouseout of nested div question

开发者 https://www.devze.com 2022-12-18 14:19 出处:网络
I\'m trying to fire a function on the mouseout of a div.However when you mousover an element in the div it fires the mouseout.

I'm trying to fire a function on the mouseout of a div. However when you mousover an element in the div it fires the mouseout.

<div id="my_div">
    <div class="another_div">X</div>
</div>

<script>
$("#my_div").mouseout(function () {
    alert('weeeee, I am out!');
}
</script>

This makes sense but how can I test for the mouseo开发者_如何学Cut event only if it is not on a child element?


Try using the MouseLeave event rather than the mouseout, according to the API:

Mouseout fires when the pointer moves into or out from child element, while mouseleave doesn't.


you want this:

http://docs.jquery.com/Events/mouseenter and http://docs.jquery.com/Events/mouseleave

0

精彩评论

暂无评论...
验证码 换一张
取 消