First case:Second case:Effect:First case: Click on the Orange column, alert ("Child1"), Alert ("Parent1")Click on the Yellow section, alert ("Parent1")Second case: Click on the gray Light Section, alert ("Child2")Click on the rest of the section, alert ("Parent2")That is, in the second case, using the event.cancelbubble () =true prevents the bubbling sort.-------------------------Bubble sort, when a child element is triggered, the
(); Take the upper limit2, Math.floor (); Lower limit3, math.sqrt (); Open Square4, Math.Round (); Rounded5, Math.random (); Random number, between 0-1.Iv. EventsOnClick Mouse Single TriggerOnDblClick Mouse double-click Triggeronmouseover Mouse Move-in triggeronmouseout Mouse move out TriggerOnMouseMove Mouse on top move triggeronchange content Change Triggeronblur Loss of Focus trigger (focus refers to the cursor position)Onfocus Get intersection TriggerOnKeyDown Press the button to triggeronk
. However, clicking a label also doesn't happen because it is also a descendant element. In fact, we can not put the check code here, but by modifying the behavior of the button to achieve the goal . 2. Stop Event PropagationThe Event object also provides a . Stoppropagation () method that can completely block event bubbling
Before the incident bubbling problem, also went to the internet to search for some, the results are mostly the same code, posted to the time is not very smooth. When it comes to FF, you can use E.stoppropagation (); , somehow I didn't succeed. However, I find that FF supports e.cancelbubble = True, and is tested and feasible. Just post the code here, and the province can look everywhere. The compatibility of previous versions of IE has not been tested
1. Event.preventdefault (); --Block The default event for an element.Note: The click of a element to jump to the default event,Default events for form elements such as Button,radio,div element has no default eventCases:href= "http://www.baidu.com" target= "_black"> Baidu a>var samp = Document.getelementbytagname ("a"); Samp.addeventlistener ("click",function (e) {E.preventdefault ()},false);Explanation: Cl
Blocking JavaScript event bubbling transfer (cancelBubble, stopPropagation) cancelBubble is valid in IE
StopPropagation is valid in Firefox
The Code is as follows:
Prevents JavaScript event bubbling transfer (cancelBubble, stopPropagation)
This article mainly introduces the principle of javascript event bubbling. The example analyzes the definition and implementation skills of event bubbling. If you need it, you can refer to the example below to describe javascript event b
This article mainly introduces the principle of javascript event bubbling. The example analyzes the definition and implementation skills of event bubbling. if you need it, you can refer to the example below to describe javascript event b
1.targetBy getting DOM elementsvar box = document.getElementById ("box");Document.box.onclick = function () {alert (123);//123}Target method under the event object: Gets the target of the event, without document.getElementById ("box") to obtain the target;Under theDocument.onclick = function (evt) {var e = evt | | window.event;alert (e.target.tagname); DIV IE7 below for Undefind}For srcelement under IEDocum
In JQuery, how does one prevent event bubbles? This article provides two methods to prevent event bubbles. The difference between the two methods is. Returnfalse not only prevents events from bubbling up, but also prevents events. JQuery provides two methods to prevent event bubbli
Javascript event bubbling1 event
On the browser client application platform, events are basically triggered, that is, an event occurs, and then corresponding actions are taken.
Browser events indicate the signal of some events. The description of the event is not the focus of this Article. If you have not yet understoo
Bubble event is to click on the child node, the event will be passed up, and finally triggered the parent node, ancestor node Click event.
HTML code section:
Copy Code code as follows:
Outer DIV Element
Outer DIV Element
The jquery code is as follows:
Copy Code code as follows:
When you click Span, it trigge
What is bubbling? On the page, you can have multiple events or multiple elements to respond to the same event. Assume that there are two elements on the webpage, one of which is nested in the other, and both are bound to the click event, and the click event is also bound to the body element. 01 lt; divid quot; conten
This article mainly introduces jquery event bubbling and how to prevent jQuery event bubbling. For more information, see
I. What is jquery event bubbling?
Many textbooks or manuals may involve the concept of
The bubbling event is a click on the child node, which triggers the parent node, the ancestor node's click event. When you click Span, the div and body click events are triggered. Clicking on a div triggers the body's Click event.How do you prevent this bubbling event from
However, in some large web interaction projects today, such as large webgame projects, the influence of JavaScript event bubbling is worth noting. This article uses a simple example to explain the Javascript event bubbling and precautions.
If you don't have any idea about JavaScript
This article mainly introduces jquery event bubbling and how to prevent jQuery event bubbling. For more information, see
I. What is jquery event bubbling?
Many textbooks or manuals may involve the concept of
1. Event ObjectivesThe event object is now stored in the event handler for the variable event. The Event.target property holds the target element where the event occurred. This attribute is specified in the DOM API, but is not implemented by all browsers. jquery makes the ne
The 1.javascript Dom is nested with each other, and when the child element is clicked, the event is triggered on the child element, and then the event is passed up the level. This is called event bubbling.Event.stoppropagation (); You can stop event bubbling, that is, no lon
jquery's prevention of bubbling eventsThe bubbling event is a click on the child node, which triggers the parent node, the ancestor node's click event.Here is the HTML code section:"content"> outer div element outer div element "msg">The corresponding jquery code is as follows:When you click Span, the div and body click events are triggered. Clicking
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.