JS Event Event.preventdefault () and event.stoppropagation () usage difference

Source: Internet
Author: User

Introduction to Event.preventdefault () usage

This method notifies the Web browser not to perform the default action associated with the event, if such an action exists. For example, if the Type property is "Submit," any event handle can be invoked at any stage of the event propagation, and by invoking the method, the form can be blocked. Note that if the Cancelable property of the Event object is Fasle, there is no default action, or the default action cannot be blocked. In either case, calling the method has no effect.

This method notifies the Web browser not to perform the default action associated with the event, if such an action exists.

For example, if the Type property is "Submit," any event handle can be invoked at any stage of the event propagation, and by invoking the method, the form can be blocked.

Note that if the Cancelable property of the Event object is Fasle, there is no default action, or the default action cannot be blocked. In either case, calling the method has no effect.

Introduction to Event.stoppropagation () usage

This method stops the propagation of the event and prevents it from being dispatched to another Document node. It can be invoked at any stage of the event propagation. Note that although this method cannot prevent other event handles from being invoked on the same Document node, it can prevent the dispatch of events to other nodes

This method stops the propagation of the event and prevents it from being dispatched to another Document node. It can be invoked at any stage of the event propagation.

Note: Although this method cannot prevent other event handles from being invoked on the same Document node, it can prevent the dispatch of events to other nodes.

The event is a DOM method of events, so it is not used alone, such as specifying DOM

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.