JavaScript event bubbling

Source: Internet
Author: User

The 1.javascript Dom is nested with each other, and when the child element is clicked, the event is triggered on the child element, and then the event is passed up the level. This is called event bubbling.

Event.stoppropagation (); You can stop event bubbling, that is, no longer passing events to superiors.

2. Event delegation, because events are passed up and down, so we can delegate functions that would otherwise be executed by child elements to the parent element. The helper child element executes the function after the parent element captures the event to the child element.

Event.target the element that triggered the event

Event.currenttarget the element that currently captures the event

3.jquery handling of Event delegates: delegate (SELECTOR,[TYPE],[DATA],FN)

type: One or more events attached to the element. Multiple event values are separated by a space. Must be a valid event.

Data: Additional data passed to the function

fn: A function that runs when an event occurs

Overview:

The specified element (which belongs to the child element of the selected element) adds one or more event handlers and specifies the function to run when these events occur.

Event handlers that use the delegate () method apply to current or future elements, such as new elements created by a script.

3.dom2 level Event function, add Event AddEventListener (type,function,iscatch), remove event RemoveEventListener

Iscatch whether to capture, true: Capture, false: bubbling. event handling mechanism, bubble compatibility is better.

JavaScript 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.