AddEventListener's third argument

Source: Internet
Author: User

The event broadcast in JS is divided into three phases: event capture, event-handling invocation, event bubbling.

1. Event capture: Walk down the DOM tree to the inside of a node

2. Event invocation: An event handler defined on a node (e.g. click Mouseove, etc.)

3. Event bubbling: Move up from this node along the DOM tree. (This will call the parent element's event-handling call, which can be used with stoppropagation in IE cancelbubble)

Look at the third parameter of AddEventListener () after you know the event broadcast. is a Boolean value, and False is event bubbling (that is, in phase Three), and true is event capture (that is, in the first phase).

In fact, there are only two parameters, but IE is event bubbling, so the third parameter is defined. However, the order of IE event bubbling is more in line with People's Daily thinking (so IE is not useless), so it is wrong to change.

But what's the point?

When it went to phase three, the problem came.

If the parent-child node has click event Handling, when we click on the child node.

Will first call the child node's click,

This will bubble to the parent node.

Then call the parent node's click.

But we don't need the parent node click.

At this time need to call Stoppropagation (), in IE to use cancelbubble ();

The end of this article



The Code is poetry.

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.