Jquery stops event bubbling event.stopPropagation_jquery
Description: Prevent events from bubbling up the DOM tree, that is, event handlers on any predecessor elements are not triggered.
version added: 1.0
event.stopPropagation()
We can use event.isPropagationStopped() to determine whether this method has been called (on that event object).
This method is also valid for custom events triggered by trigger().
Note that this does not prevent other event handlers on the same element from running.
Additional Notes:
Since the .live() method handles the event once it propagates to the top of the document, it is impossible for the live event to stop propagating. Likewise, .delegate() events will always be propagated to the contained delegated element; events on the element will be executed when the delegated event is called.
Example:
Stop the bubbling of click events.
$("p").click(function(event ){
event.stopPropagation();
// do something
});
Things are not difficult, the main thing is to record the prevention event Bubble.
Because the div has added a click event, and the img inside the div has also added a click event, so when the img is clicked, the click event on the img will be triggered first, and then the click event on the div will be triggered. This is event bubbling.
We can easily stop him in Jquery.
As follows
In this way, clicking the img will no longer trigger the click event of the div
$('div').click(function(){
var $div = $(this);
if($div.find(' img').size() > 0){
return;
}else{
$div.css('backgroundColor','#e1f0f3');
$('

appendTo($(this)).click(function(event){
$div .css('backgroundColor','#ffffff');
$(this).remove();
event.stopPropagation();
}).css('margin-left','10px ');
}
});

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Understanding event bubbling: Why does a click on a child element trigger an event on the parent element? Event bubbling means that in a nested element structure, when a child element triggers an event, the event will be passed to the parent element layer by layer like bubbling, until the outermost parent element. This mechanism allows events on child elements to be propagated throughout the element tree and trigger all related elements in turn. To better understand event bubbling, let's look at a specific example code. HTML code: <divid="parent&q

Click events in JavaScript cannot be executed repeatedly because of the event bubbling mechanism. To solve this problem, you can take the following measures: Use event capture: Specify an event listener to fire before the event bubbles up. Handing over events: Use event.stopPropagation() to stop event bubbling. Use a timer: trigger the event listener again after some time.

Title: Reasons and solutions for the failure of jQuery.val() In front-end development, jQuery is often used to operate DOM elements. The .val() method is widely used to obtain and set the value of form elements. However, sometimes we encounter situations where the .val() method fails, resulting in the inability to correctly obtain or set the value of the form element. This article will explore the causes of .val() failure, provide corresponding solutions, and attach specific code examples. 1.Cause analysis.val() method

Why does event bubbling trigger twice? Event bubbling (Event Bubbling) means that in the DOM, when an element triggers an event (such as a click event), the event will bubble up from the element to the parent element until it bubbles to the top-level document object. . Event bubbling is part of the DOM event model, which allows developers to bind event listeners to parent elements, so that when child elements trigger events, the events can be captured and processed through the bubbling mechanism. However, sometimes developers encounter events that bubble up and trigger twice.

Vue.js event modifiers are used to add specific behaviors, including: preventing default behavior (.prevent) stopping event bubbling (.stop) one-time event (.once) capturing event (.capture) passive event listening (.passive) Adaptive modifier (.self)Key modifier (.key)

What is event bubbling? In-depth analysis of the event bubbling mechanism Event bubbling is an important concept in web development, which defines the way events are delivered on the page. When an event on an element is triggered, the event will be transmitted starting from the innermost element and passed outwards until it is passed to the outermost element. This delivery method is like bubbles bubbling in water, so it is called event bubbling. In this article, we will analyze the event bubbling mechanism in depth. The principle of event bubbling can be understood through a simple example. Suppose we have an H

What are the situations in JS events that will not bubble up? Event bubbling (Event Bubbling) means that after an event is triggered on an element, the event will be transmitted upward along the DOM tree starting from the innermost element to the outermost element. This method of transmission is called event bubbling. However, not all events can bubble up. There are some special cases where events will not bubble up. This article will introduce the situations in JavaScript where events will not bubble up. 1. Use stopPropagati

What are the JS events that will not bubble up? JavaScript is a powerful scripting language that adds interactivity and dynamics to web pages. In JavaScript, event-driven programming is a very important part. Events refer to various operations performed by users on web pages, such as button clicks, mouse movements, keyboard input, etc. JavaScript responds to these events through event handling functions and performs corresponding operations. Event bubbling is a common mechanism during event processing. Event bubbling means that when an
