jQuery event.stopPropagation()Method
Example
Prevent the click event from bubbling to the parent element:
$("span").click(function(event){
event.stopPropagation();
alert("The span element was clicked.");
});
$("p").click(function(event){
alert("The p element was clicked.");
});
$("div").click(function(){
alert("The div element was clicked.");
});
event.stopPropagation();
alert("The span element was clicked.");
});
$("p").click(function(event){
alert("The p element was clicked.");
});
$("div").click(function(){
alert("The div element was clicked.");
});
Try it Yourself »
Definition and Usage
The event.stopPropagation() method prevents the event from bubbling to the parent element and prevents any parent event handlers from being executed.
Tip:Please use theevent.isPropagationStopped()method to check whether this method was called on the specified event.
Syntax
event.stopPropagation()
| Parameters | Description |
|---|---|
| event | Required.eventThe parameter comes from the event binding function. |
Other Extensions
jQuery Event Methods