In jQuery, what is the difference between mouseleave
and mouseout
?
The two events seem to do the same thing!
In jQuery, what is the difference between mouseleave
and mouseout
?
The two events seem to do the same thing!
Basically, the only difference between the two is that mouseleave
is also fired on the child elements of the selected element, and mouseout
fires only on the selected element.
x = 0;
y = 0;
$(document).ready(function(){
$("div.over").mouseout(function(){
$(".over span").text(x += 1);
});
$("div.enter").mouseleave(function(){
$(".enter span").text(y += 1);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script><divclass="over" style="background-color:lightgray;padding:20px;width:250px;float:left">
<h3 style="background-color:white;">Mouseout disparado: <span></span></h3>
</div>
<div class="enter" style="background-color:lightgray;padding:20px;width:250px;float:right">
<h3 style="background-color:white;">Mouseleave disparado: <span></span></h3>
</div>
Here you can check out more about these two events events:
Suppose we have the following HTML (where each div has mouseout events, mouseleave trailers):
<div id="outerBox">OuterBox
<div id="innerBox">InnerBox
</div>
</div>
When the mouse leaves "outerBox" your event is fired.
As soon as you can see that the differences between the two are related to your "children", " mouseleave " is also fired in the child elements while the mouseover selected.
Source: link