The difference between mouseover and MouseEnter, Mouseout and MouseLeave

Source: Internet
Author: User

The MouseOver event is triggered regardless of whether the mouse pointer passes through the selected element or its child elements.

The MouseEnter event is triggered only when the mouse pointer passes through the selected element.

The test code is as follows:



<script type= "Text/javascript" src= "/jquery/jquery.js" ></script>
<script type= "Text/javascript" >
x=0;
y=0;
$ (document). Ready (function () {
$ ("Div.over"). MouseOver (function () {
$ (". over span"). Text (x+=1);
});
$ ("Div.enter"). MouseEnter (function () {
$ (". Enter span"). Text (y+=1);
});
});
</script>

<body>
<p> triggers the MouseOver event regardless of whether the mouse pointer passes through the selected element or its child elements. </p>
<p> The MouseEnter event is triggered only when the mouse pointer passes through the selected element. </p>
<div class= "Over" style= "Background-color:lightgray;padding:20px;width:40%;float:left" >


</div>
<div class= "Enter" style= "Background-color:lightgray;padding:20px;width:40%;float:right" >


</div>
</body>

The results are as follows:

The difference is whether the child element can trigger the function!

The difference between mouseover and MouseEnter, Mouseout and MouseLeave

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.