jquery blocks bubbling and HTML default actions

Source: Internet
Author: User

jquery is a quick and easy JavaScript framework, saying that the framework can be directly understood to be the encapsulation of the original underlying so that developers can use this framework to develop quickly.1:jquery is a quick and easy JavaScript framework, saying that the framework can be directly understood as the encapsulation of the original underlying so that developers can use the framework to develop quickly.

2: Event bubbling is supported in every browser today, so-called bubbling can be understood as:

Condition: There is a DIV element in the outer layer, there is a P element in the inner layers, he has two such relations: the div is the parent element of the P element, and P is the child of the outer Div, and there is a relationship between them that contains and is contained.
Event: Now we all bind the same event on these two elements, such as the Click event.
Result: At this point, when we click on the P tag in the inner layer, the click event of the inner element is triggered, and the click event of the outer div is triggered.
3: Some of the elements in the HTML are defined by default properties, such as a element, which is the hyperlink tag that we usually use, the default property of this tag is to implement the page jump.
4: In each event of jquery, there is a default object as an argument to the event (but must be specified), which is the event object, which contains properties and methods for different occasions. As follows:
$ (' P:first '). Click (Function (event) {
The event object can use the
});
5: Sometimes we don't want bubbles or default events to happen, so it takes some jquery methods to block bubbles and default events. There are three ways to prevent different levels of blocking.
A:return False--->in event handler, prevents default behavior and event bubbing.
return false in the handling of events, you can block default events and bubbling events.
B:event.preventdefault ()---> in event handler, prevent default event (allows bubbling).
Event.preventdefault () in the handling of the event, you can block the default event but allow the bubbling event to occur.
C:event.stoppropagation ()---> in event handler, prevent bubbling (allows default behavior).
Event.stoppropagation () in the handling of the event, you can prevent bubbling but allow the default event to occur.
Code such as:
$ ('. Menu Li '). Click (function () {
$ (this). Find (' ul '). Toggle ();
return false;Remove the trial effect
})

jquery blocks bubbling and HTML default actions

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.