The difference between mouseover, mouseout, MouseEnter and MouseLeave in jquery

Source: Internet
Author: User

The MouseOver event is triggered regardless of whether the mouse pointer passes through the selected element or its child elements, and corresponds to the mouseout
The MouseEnter event is triggered only when the mouse pointer passes through the selected element, which corresponds to the MouseLeave

The following example can help us to understand the difference between mouseover and MouseEnter:

1 <HTML>2 <Head>3 <Scripttype= "Text/javascript"src= "/jquery/jquery.js"></Script>4 <Scripttype= "Text/javascript">5 x=0;6 y=0;7 $ (document). Ready (function(){8   $("Div.over"). MouseOver (function(){9     $(". Over span"). Text (x+=1);Ten   }); One   $("Div.enter"). MouseEnter (function(){ A     $(". Enter Span"). Text (y+=1); -   }); - }); the </Script> - </Head> - <Body> - <Divclass= "Over"style= "Background-color:lightgray;padding:20px;width:40%;float:left"> + <H2style= "Background-color:white;">The Mouseover event that is triggered:<span></span></H2> - </Div> +  A <Divclass= "Enter"style= "Background-color:lightgray;padding:20px;width:40%;float:right"> at <H2style= "Background-color:white;">The Mouseenter event that is triggered:<span></span></H2> - </Div> - </Body> - </HTML>

1, $ ("Div.over"). MouseOver, when the mouse enters the <div></div> tag will count plus 1, when the mouse enters the

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

2, $ ("Div.over"). MouseEnter, when the mouse enters the <div></div> tag will count plus 1, when the mouse into the

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

Second, the following example can help us to understand the difference between mouseout and MouseLeave:

1 <HTML>2 <Head>3 <Scripttype= "Text/javascript"src= "/jquery/jquery.js"></Script>4 <Scripttype= "Text/javascript">5 x=0;6 y=0;7 $ (document). Ready (function(){8   $("Div.out"). Mouseout (function(){9     $(". Out span"). Text (x+=1);Ten   }); One   $("Div.leave"). MouseLeave (function(){ A     $(". Leave span"). Text (y+=1); -   }); - }); the </Script> - </Head> - <Body> - <Divclass= "Out"style= "Background-color:lightgray;padding:20px;width:40%;float:left"> + <H2style= "Background-color:white;">The Mouseout event that is triggered:<span></span></H2> - </Div> + <Divclass= "Leave"style= "Background-color:lightgray;padding:20px;width:40%;float:right"> A <H2style= "Background-color:white;">The MouseLeave event that is triggered:<span></span></H2> at </Div> - </Body> - </HTML>

1, $ ("Div.over"). Mouseout, when the mouse leaves the <div></div> tag will count plus 1, when the mouse left the

The Mouseout event is triggered regardless of whether the mouse pointer leaves the selected element or any child elements.

As shown, the Mouseout event is triggered at three blue dot locations.

2, $ ("Div.over"). MouseLeave, when the mouse leaves <div></div> tag will count plus 1, when the mouse left the

The MouseLeave event is triggered only when the mouse pointer leaves the selected element.

As shown, the MouseLeave event is triggered at the location of the blue Dot.

The difference between mouseover, mouseout, MouseEnter and MouseLeave in jquery

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.