Details about javascript event bubbling _ javascript skills

Source: Internet
Author: User
This article mainly introduces javascript event bubbling and javascript implementation code to prevent event bubbling. If you are interested, you can refer to the event as one of the core content in javascript, an important concept is inevitably involved in the application of events, that is, event bubbling. Before introducing event bubbling, we should first introduce another important concept of event stream:
1. What is event stream:
The Document Object Model (DOM) is a tree structure that can be represented in images.

If an html element triggers an event, the event will be transmitted between the trigger node and the root node in the DOM tree in a certain order, and all the nodes that pass through will receive the triggered event, this propagation process is called an event stream. Events can be divided into two categories according to the propagation order. One is event bubbling and the other is event capture. Here we will discuss the topics to be discussed in this chapter:
1. Event bubbling:
The so-called time bubble is when an element triggers an event, the event will be like a bubble, from the trigger element to all its parent nodes, until the root node will receive this event, if the corresponding event handler function is registered in the parent element, even if the event is triggered on the child node, the event handler function registered on the parent element will also be triggered. For example, in the figure above, if the onclick event of Element a is triggered, its parent elements p, document, and widow will receive the event, if the corresponding parent element registers a time-consuming processing function, the event processing function will be executed. Check a code example:

 Simple introduction to event 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.