A doubt about the propagation of JS events

Source: Internet
Author: User

When learning events spread, a problem was found, at that time.

I've bound bubbling and capturing events to multilayer elements, respectively. As a matter of principle, you should perform all the capture events from the outside, and then all the bubbling events from inside out.

But God does not want to do, there is an element that happens to be the bubbling event, and then the capture event is executed.

I did not understand how to check the information, then put down. Today I suddenly find myself this unruly element that just happens to be the innermost element of all my BOM elements.

I just thought, maybe it's the browser that doesn't differentiate whether the event it's bound to is capturing or bubbling.

So I proved it:

First: I first put the most inner elements of the capture events and bubbling events in the registration order, found that the order of execution also changed YES! It seems that there is no distinction between the AH!

Second: I add another layer of elements to the innermost element, and when you trigger on the newly added element, you find that the two events are finally executed according to the rules.

It is now clear that when you trigger a most specific element, the event of the element itself is not bubble-sensitive or captured.

A doubt about the propagation of JS events

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.