jquery Time Bubbles

Source: Internet
Author: User

event bubbling : When an event on an element is triggered, such as a mouse click on a button, the same event will be triggered in all ancestor elements of that element. This process is known as event bubbling, which bubbles to the top of the DOM tree from the beginning of the original element. That is, when the nesting of multiple div is set up, that is, the parent-child relationship is established, when the parents Div joins the onclick event with the sub-Div, when the onclick event of the sub-div is triggered, the sub-Div makes the corresponding JS operation. But the OnClick event of the parent Div is also triggered. This creates multiple levels of concurrency for the event, resulting in page clutter. This is the bubbling event.

Ways to block JavaScript events from bubbling delivery:

1.event.stoppropagation ();

$ (document). Ready (function (){     $ (' div '). Click (Function (event) {        alert (' div ');     } );     $ (' P '). Click (Function (Event){        alert (' P ');     } );     $ (' span '). Click (Function (Event){        alert (' span ');        Event.stoppropagation ();     } ) });

<div>div Element
<p>paragraph element<br/>
<span>span element</span>
</p>
</div>

2.return (FALSE);

$ (document). Ready (function (){    $ (' div '). Click (Function (event) {        alert (' div ');    } );    $ (' P '). Click (Function (Event){        alert (' P ');    } );    $ (' span '). Click (Function (Event){        alert (' span ');        return (false);    } )}); <div>div Element    <p>paragraph element<br/>        <span>span Element</span >    </p></div>

Difference: return false not only prevents the event from bubbling up, but also blocks the event itself. Event.stoppropagation () Only blocks events from bubbling up, not blocking the event itself.

jquery Time Bubbles

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.