Event bubbling usage Example for event object E in jquery (event bubbling and block bubbling)

Source: Internet
Author: User

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> event bubbling and blocking Bubbles </title>
<script src= "Js/jquery.min.js" type= "Text/javascript" ></script>
<body>
<script type= "Text/javascript" >
$ (function () {
$ ("Div li"). Click (function (e) {
Alert ("I Am Li");
})
$ ("Div ul"). Click (function (e) {//This E is actually an event object
Alert ("I am ul");
E.stoppropagation (); E.stoppropagation (); Stop bubbling, if not write this, after the "I Am Li" pops up "I am ul", then will pop up "I am div". Add E.stoppropagation () here, and then, "I am div" will not pop out. Because it has been stopped. In fact, this sentence can also be replaced with return false
})
$ ("div"). Click (function (e) {
Alert ("I am div");
})
})
</script>
<div>
<ul>
<!--Li in UL, ul in the Div, as long as the click on the Li, that is, click on the UL, that is, click the Div. In the above function, the first "I Am Li" pops up and then pops up "I am ul", and finally pops up the "I am div" layer of bubbling, and the way to block bubbles is to invoke the object of the event to invoke the Stoppropagation () method. The object of this event is the function's argument e, the name of E can be easily
<li> Please click on my </li>
</ul>
</div>
</body>

Event Bubbling Usage Example for event object E in jquery (event bubbling and block bubbling)

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.