Latest web development tutorials

jQuery event.stopPropagation () method

jQuery Event Methods jQuery Event Methods

Examples

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.");
});

try it"

Definition and Usage

event.stopPropagation () method prevents the event from bubbling to the parent elements, preventing any parent event handler is executed.

Tip: Use event.isPropagationStopped () method to check whether this method is called on a specified event.


grammar

event.stopPropagation()

参数 描述
event 必需。 event 参数来自事件绑定函数。


jQuery Event Methods jQuery Event Methods