JavaScript event bubbling and canceling bubbling

Source: Internet
Author: User

Event bubbling: When an event on an element is triggered, such as a mouse click on a button, the same event will be triggered in all ancestors of that element, a process known as event bubbling.

This event starts from the original ancestor and bubbles to the top of the DOM tree. (bug)

(I should have done it alone, but I did something wrong and you told my mom)

Simply put, bubbling is: The child element event is touched, and the same event of the parent box is touched.

Canceling bubbling is canceling this mechanism.

Block bubbling:

Firefox, Google, IE11:event.stopPropagation ();

IE10 below: Event.cancelbubble = true;

Compatible Code:

A.onclick = function (event) {

Stop bubbling
Event = Event | | window.event;
if (event && event.stoppropagation) {
Event.stoppropagation ();
}else{
Event.cancelbubble = true;
}

}

JavaScript event bubbling and canceling bubbling

Related Article

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.