Javascript event bubbling

Source: Internet
Author: User

Javascript event bubbling
1 event

On the browser client application platform, events are basically triggered, that is, an event occurs, and then corresponding actions are taken.

Browser events indicate the signal of some events. The description of the event is not the focus of this Article. If you have not yet understood it, you can visit the W3school tutorial to learn about it. This will help you better understand the following content.


Binary bubble Mechanism

In javascript, the bubble mechanism is different from the concept in the algorithm data structure. The main feedback here is a bubble feedback process after event capture in the event flow process.


As shown in this figure, this bubble is equivalent to an event here, while water is equivalent to our entire dom tree. Events are transmitted from the bottom layer of the dom tree, to the root node of the dom. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + 0rK + zcrHyOfPws28PC9wPgo8cD48aW1nIHNyYz0 = "http://www.2cto.com/uploadfile/Collfiles/20140814/20140814091511180.png" alt = "\">

Here, I will write a simple case for analysis;

 Event bubbling case




Add a click event for it

 Event bubbling case





Generally, an event contains some information during transmission, which is an integral part of the event: event occurrence time + Event Location + Event Type + current handler of the event + other information,

B. Terminate the event bubble.
 Event bubbling case<Script type = "text/javascript"> window. onload = function () {var odiv = document. getElementById ('div3 '); odiv. onclick = function (ev) {var Event = ev | event; Event. alert ("to be blocked"); Event. cancelBubble = true ;}}</script>

After cancelBubble is added, click the bubble event of the div3 layer to stop it.



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.