JS Block event bubbling return false/e.stoppropagation ()/e.preventdefault ()

Source: Internet
Author: User

As each element is triggered in the document, it will bubble

If there are alert events on each layer, then the inner div is triggered, the outer layer, the outermost layer.

To prevent interference between events, you need to block event bubbling.

General use of e.stoppropagation ();

IE8 and below do not support, need to use e.cancelbubble=false;

Another e is the global object used to get the window. E can use any other letter or Word instead, such as a,b,c,d....,event,obj and so on.

Whenever an event is triggered, the system will pass an object to the event to obtain a global object.

For example, through E to get global object Stoppropagation (), Cancelbubble,pagex,pagey, which can be seen through the page Console.info ().

E.stoppropagation (), also equivalent to return false;

Just return false there are other actions that prevent the default behavior of the event, such as the default jump href for the submit button submit,a tag, and so on.

return false; equal to E.preventdefault ();

E.preventdefault () cannot prevent the event from bubbling, only the triggering of the event's default behavior is blocked.

Return false contains two features that block event bubbling and block the default behavior.

Therefore, in development, it is customary to use return false.

JS Block event bubbling return false/e.stoppropagation ()/e.preventdefault ()

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.