Event capture, event bubbling, and event delegation in Javascript

Source: Internet
Author: User
Tags id3
Event bubbling: the deepest element of event promotion first receives events. Then, the parent element of the object goes up until the document Object finally receives the event. Although a document does not have an independent visual representation relative to an html element, it is still the parent element of an html element and events can bubble to the document element.

Concept

Event bubbling: the deepest element of event promotion first receives events. Then, the parent element of the object goes up until the document Object finally receives the event. Although a document does not have an independent visual representation relative to an html element, it is still the parent element of an html element and events can bubble to the document element.
Let's talk about event capture.
Event Capture: events first occur on the top object (document) of the DOM tree and then spread to the deepest element. (Note that IE6 is only bubble and not captured)
Event delegation: I think event delegation converts event listening to its parent element by using the bubble principle, that is, binding the event to the parent element, then, obtain the child element object in the event and perform corresponding operations on it. Advantages: 1. Improve performance 2. Reduce the amount of code

Instance event bubbling instance 1

Events are executed in the bubble stage by default.
First, check the following code:

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.