jquery event propagation, event flow

Source: Internet
Author: User

I. jquery event dissemination

In the DOM2-level event model, once an event is triggered. The event stream is first propagated down from the top of the DOM tree (the document node). Until the target node. It then propagates upward from the target node to the top of the DOM tree. The process from top to bottom is called the capture phase. The process from bottom to top is called the bubbling phase.

A capture mouse Click class event handler for the button element and all of its parent nodes, respectively, using the loop body structure.

Sample Code Demo:

<! DOCTYPE html>

The following changes are made to the 3rd parameter of the AddEventListener () method, setting the value to False, that is, the register event is a bubbling handler.

<script type= "Text/javascript" >    window.onload = function () {        var btn = document.getElementsByTagName (" Input ") [0];//Gets the button        var p = document.getelementsbytagname (" P ") [0];//p element        var i = 1;//declare and initialize a transient variable        do{// Use the Do loop structure to register the mouse click event            btn.addeventlistener ("click", Function () {//Register mouse click event                p.innerhtml + = "<br/> ("  + i++ + ")  "  + this.nodename;        },false);//Dynamically track the name of the current response node                this.removeeventlistener ("click", Arguments.callee,false);//Unregister the current mouse click event            btn = Btn.parentnode;//access to the parent element        } while (BTN);//Set the loop condition, assuming the parent node exists    }</script>

Two. jquery Event flow

Sample code Demo:

<! DOCTYPE html>





jquery event propagation, event flow

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.