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
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
Compatible with Firefox, Google and other browsers functionStopevent (event) {//Block Bubbling Events //Cancel Event Bubbling vare=arguments.callee.caller.arguments[0]| | Event//If this sentence is omitted, the following e will be changed to
Stop event bubbling and "block browser default behavior" are frequently used in front-end development work due to browser compatibility issues.
1. Block browser default behavior [Java] View plain copy Functionstopdefault (e) { //If an event object is provided, this is a non-ie browser if (ee.preventdefault) { //block default browser actions (web) E.pr
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
1.E.preventdefault () block event default behaviorE.preventdefault ();----according to English meaning, such as: $ ("#xx"). Click (function (e) {Alert ("xxx");E.preventdefault ();}); ----------------------------------this time will pop up "xxx", will not jump to href==2.e.stoppropagation () block event bubblingEvent bubbling is all from the inside out.$ (". PP").
Transferred from: http://wyqbailey.diandian.com/post/2012-07-12/40030551971return FalseIn jquery, we often use return false to block the browser's default behavior, what does "return false" actually do?When you call "return false" every time, it actually does 3 things:
Event.preventdefault ();
Event.stoppropagation ();
Stops the callback function execution and returns immediately.
Yes, you are right, return false does so many things. It's been used repeatedly because it loo
Here is the HTML code section:
Copy Code code as follows:
Outer DIV Element
Outer DIV Element
The corresponding jquery code is as follows:
Copy Code code as follows:
When you click Span, it triggers the div and body click events. Clicking on the div triggers the body's Click event.
How do you prevent this bubbling even
Click a box to pop up, but sometimes you don't want to operate it. You just want to click a blank space to hide the box. The following is a specific implementation:Most of the time, we have such a small function when doing front-end operations. Click a box to pop up. However, if you don't want to operate it, you just want to click a blank space to hide the box. In the following scenario, click a small button to bring up a modal box. This is simple, but we want to hide the modal box when you clic
But we clicked on the three elements that were under the user's mouse pointer, and element is irrelevant to this interaction. Event capture is first handed to the outermost element, and then to a layer of The other opposite strategy is that the most specific elements get a chance to respond before bubbling to more general elements. The solution: Example: 1. Event
function Stopbubble (e) {Commonly used on mouse or keyboard eventsif (e e.stoppropagation) {The consortium cancels bubbling eventsE.stoppropagation ();}else{IE Cancel bubbling EventWindow.event.cancelBubble = true;}};
1, cancelbubble (HTML DOM Event object property): If the event handle wants to prevent an
Let's talk about how javascript events cancel and block bubbling, and talk about javascript
Cancel default operation
The w3c method is e. preventDefault (), and IE uses e. returnValue = false;
In browsers that support addEventListener (), you can also call the preventDefault () method of the time object to cancel the default operation of the time. However, in IE
Thanks for browsing, welcome to Exchange =. =
Company development Web pages need to use pop-up windows, the use of Jquery-ui custom download still need more than 150 KB, want some luxury (finally down only 11kb, compression 2kb, ah, my God),Mobile phone side pop-up windows and PC side somewhat different, and the phone has a pop-up window rolling with the parent page scrolling interaction problems,So decided to write a plug-in, specifically against the mobile phone page pop-up window.The Ma
First explain the event bubbling God what,In JS, if you nest a div in a divSuch asstyletype= "Text/css">#box1{width:500px;Height:500px;background:#900;}#box2{width:400px;Height:400px;background:#090;}#box3{width:300px;Height:300px;background:#009;}#box4{width:200px;Height:200px;background:#990;}#box5{width:100px;Height:100px;background:#099;}style>Body>DivID= "Box1"> DivID= "Box2"> DivID= "Box3">
Prevent event bubblingBy default, Knockout allows the Click event to continue bubbling execution on a higher level event handle. For example, if both your element and the parent element are bound to the Click event, then two events will trigger when you click on the element.
The MouseOver () method triggers the MouseOver event, or the function that runs when the MouseOver event occurs
The Mouseout () method triggers the Mouseout event, or a function that runs when the Mouseout event occurs.
First look at an example
code is as follows
copy code
function
I. Introduction to bubbling EventsWhen we click on a control, if the parent control that includes the control also has the Click event, it will continue to execute.Method One: Event.stoppropagation ();For example:Paragraph text content Type="Button" Value=Click /> HTML code:Bind the Click event for all DIV elements$("Div").Click( function(
The bubbling event is the order in which the bubbles are triggered from the bottom up to the outside.Window.onload =function() { //The bubbling event is the order in which the bubbles are triggered from the bottom up to the outside.Document.onclick =function() {alert (' Document '); }; Document.documentElement.on
JQuery provides two ways to prevent event bubbling.Mode one: Event.stoppropagation ();$ ("#div1"). MouseDown (function (event) {Event.stoppropagation ();});Mode two: return false;$ ("#div1"). MouseDown (function (event) {return false;});But there is a difference between the two ways. Return false not only prevents the event
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.