What is the JS event bubbling? How do I prevent jquery events from bubbling? NBSP; such as the above page,divided into three layers: Divone is the outer layer, divtwo middle layer, hr_three is the innermost layer;they all have their own click events, and the innermost a tag has an href attribute. run the page, click "Click Me", will pop up: I am the inner
Js event bubbling and js bubblingJavasrt RT events have two important features: Event bubbling and target elements.Event bubbling: when an event on an element is triggered, for example, if you click a button, the same
js block bubbling
In the process of blocking bubbles, the different methods used by the consortium and IE, then we have to do the following compatibility.
Copy Code code as follows:
function Stoppro (evt) {
var e = evt | | window.event;
ReturnValue If this property is set, its value is higher than the return value of the event handle. Set this property to Fasle,
You can cancel the def
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 ancestors of that element, a process known as event bubbling.
This
Let's look at the following sample code:HTMLxmlns= "http://www.w3.org/1999/xhtml">Head>title>Event bubbling and event capture in JavaScripttitle>Head>Body> DivID= "Red"style= "width:200px;height:200px;background-color:red;padding:20px;"> DivID= "Bule"style= "width:160px;height:160px;background-color:blue;padding:20px;"> DivID= "Yellow"style=
() {Console.log ("test2") } functiontest3 () {Console.log ("test3") } functiontest4 () {Console.log ("test4") } } Script>Body>HTML>The test results are as follows:IE6: the result is random;Ie7-8 results such as:IE9 results such as:Non-IE browser results are as follows:Due to the IE7~IE9 test results I was using a browser simulation, not sure of the results of the various browser versions of the accuracy, thus, the order of execution should be this:Capture is tri
perform the default action associated with the event.For example:Copy CodeThe code is as follows:$ ("a"). Click (Function (event) {Event.preventdefault (); Blocking the default action means that the link does not jump.Alert (4);//But this will pop up.Event.stoppropagation ();//Prevent bubbling events, the upper-level click events are not calledReturn false;//not only prevents events from
Found a small point that had not been noticed before
Stoppropagation:function () {
var e = this.originalevent;
...
if (e.stoppropagation) {
e.stoppropagation ();
}
The Stoppropagation function of the local event object called by the jquery overload stoppropagation function blocks bubbling. In other words, the current node, not the
Links: http://www.jb51.net/article/42492.htm(1) Bubbling event: The event is triggered in the order from the most specific event target to the least specific event target (Document object).(2) Capture event (
Event Flow: Describes the order in which events are received in a page event bubbling: Node (document) event captures that are received by the most specific element and then propagated up to the least specific element: the least specific node receives the event first, The mo
1.event.stoppropagation (); Event bubbling is blocked during event processing, but does not halt the default behavior (it performs a hyperlink jump)2.returnfalse; Event bubbling is blocked during event processing, and the default
Event bubbling: the deepest element of event promotion first receives events. Then, the parent element of the object goes up until the document Object finally receives the event. Although a document does not have an independent visual representation relative to an html element, it is still the parent element of an html
(1) Bubbling event: The event is triggered in the order from the most specific event target to the least specific event target (Document object).IE 5.5:div, Body, documentHTML--Document, body, IE 6.0:divMozilla 1.0:div, body, HTML, document, window(2) Capture
Suppose there are two elements on the page, one of which is nested within another element, and all are bound to the click event, and the Click event is also bound on the body Element.DOCTYPE HTML>HTMLLang= "en">Head> MetaCharSet= "UTF-8"> title>title>Head>Body>DivID= "content">Outer DIV Elementspan>Inner SPAN elementspan>Outer DIV ElementDiv>DivID= "msg">Div>Scriptsrc=".. /.. /vender/jquery-1.11.3/jqu
ObjectiveSome time ago to the freshman talk about JS events, by the way the event capture and event bubbling is how a thing, but did not give him concrete examples, here to add a sample, by the way to the rookie some specific code to see how bubbles and capture is a thing.
1. Event CaptureCapture
Talk about JavaScript events, event bubbling, event capture, and blocking default events These three topics, whether in the interview or in peacetime work, are difficult to avoid.
1. Event bubblinglet's look at a piece of code:
var $input = document.getelementsbytagname ("input") [0];
var $div = document.getel
(1) Bubbling event: The event is triggered in the order from the most specific event target to the least specific event target (Document object).IE 5.5:div, Body, documentHTML--Document, body, IE 6.0:divMozilla 1.0:div, body, HTML, document, window(2) Capture
is defined on both
(Note: AddEventListener specific use see this article DOM2 level event handling)
Click
Ie9,chrome,firefox,opera,safari supports event capture, but the versions below IE8 and IE8 only support event bubbling. Although the DOM2 specification requires that events be propagated from the Document obje
JQuery blocks event bubbling, and jquery blocks bubbling.
During our usual development process, we will certainly encounter a situation where a div (this div can be an element) wraps a div. However, events are added to both Divs, if you click the div in it, we want to handle the div event. However, we do not want the d
JS Bubbles the event by default and begins capturing all of the listener objects for that event from the root element. We can specify whether the event executes in the bubbling or capturing phase by binding the
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.