(function(e) { if (e.target == this) { $(‘#btn').toggleClass(‘hid'); }})$(‘#btn').click(function() { alert(‘btn');})
In this way, the event can be blocked.
Of course, event bubbling is not both a side effect, that is, event delegation, which is based on event
JavaScript, jquery events, event bubbling and event capture issues, the following two issues and their solutions to do a detailed summary.
Event bubbling is a process of bubbling from a child node to an ancestor node;
JavaScript, jquery events, event bubbling and event capture issues, the following two issues and their solutions to do a detailed summary.
Event bubbling is a process of bubbling from a child node to an ancestor node;
Foreword: Although proficient in jquery, but not very familiar with its prototype JavaScript, recently encountered some difficulties in learning JavaScript, such as bubbling and capturing, many times mentioned, but do not know exactly where to apply. Find some good articles for your doubts and share them here.Quirksmode a series of articles are good, easy to understand, this article is just a series of one,
Event bubbling with event capture, here is an example of capturing and bubbling in JS:HTML structure:divid="tianzi"> divid="tianzi1"> divid="tianzi2"> divid="tianzi3"> div> div> div>div>CSS style control:#tianzi{ width: px; heig
executed: first to be registered, executed first, and then executed after registration. That's what we're talking about here, and it doesn't matter whether the function bound on the target is captured or bubbling, because bubbling and capturing only affects the order of function execution on the parent element and has no effect on itself. If you do not believe,
Event bubbling
Event Capture: parent-level elements are triggered first, and child-level elements are triggered later.
Event bubbling: Child-level elements are triggered first, and parent-level elements are triggered later.
Currently, in IE and FF, trigger events ar
Although proficient in jquery, I am not very familiar with its prototype javascript. Recently I have encountered some difficulties in learning javascript, such as bubbling and capturing, which have been mentioned many times, but I do not know where the application is. I have found some good articles to explain and share them with you here.
Quirksmode has a series of articles that are both good and easy to u
Events that are bound to clicked elements occur in code order, and other elements are bubbling or capturing "perceived" events, which, according to the criteria of the standard, capture the event, and then a bubbling event occurs. The order of all events is: Other elements c
The process of capturing and bubbling events is collectively referred to as the propagation of eventsThe propagation of events can be prevented:
In the Stoppropagation () method, use the
Set cancelbubble = True under IE;
In the process of capturing stoppropagation (), the subsequent bubbling process d
is prevented from bubbling.
JQuery Code:
Copy Code code as follows:
$ ("form"). Bind (
"Submit",
function (event) {
Event.stoppropagation ();
}
);
(3) about the JS event foaming Verification
Today this problem mainly involves several keywords: objects, triggering events, capturing e
be set here. All browsers support event bubbling. Ii. Event Capture:Event capturing is the opposite of event bubbling. When an element is clicked, the event propagation direction is fr
for the event. When you click Div3 again, the Div1, Div2, and Div3 will pop up in turn, as opposed to the previous.
In IE, only event bubbling, and there is no AddEventListener event, replaced by Attachevent.
But sometimes, we don't like to have events bubbling or
1. Event.preventdefault (); --The default event that blocks the element.Note: A element of the click-Jump default event,
Default event for form elements such as Button,radio,
div element has no default event
Cases:
Copy Code code as follows:
Copy Code code as follows:
var samp =
captureStop:event.stoppropagation ();Prevent further propagation of events, including (bubbling, capturing), without parametersevent.cancelbubble = true;True to block bubbling B.Event Delegate: Uses the event bubbling feature to delegate the inner
In the process of learning jquery, we will certainly encounter the problem, that is event bubbling, then, what is the event bubbling?Event bubbling the popular point is that when you register the same
Bubbling: The event is first triggered on the target element, then the event bubbles from inside to outside its root element, which is then triggered by its parent element (such as the A-element binding click event, click A, the click event is triggered from the a element up
stability!!!So, you see above two functions "attachevent" and "AddEventListener", where "attachevent" is IE8 and its previous Internet Explorer dedicated, only support "event bubbling", "AddEventListener" is all supportedThe browser of the standard event model is dedicated to support event
Event delegation and prevention of bubbling, event delegation to prevent bubbling
Simply put, event delegation and prevention of bubbling
Html:
Js:
$ ("Ul [data-type = 'citypick']"). on ('click', function () {alert ("parent el
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.