Phương thức jQuery event.stopPropagation ()
Thí dụ
Ngăn sự kiện nhấp chuột sôi sục đến các phần tử chính:
$("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.");
});
Định nghĩa và Cách sử dụng
Phương thức event.stopPropagation () dừng việc tạo sự kiện cho các phần tử mẹ, ngăn không cho bất kỳ trình xử lý sự kiện mẹ nào được thực thi.
Mẹo: Sử dụng phương thức event.isPropagationStopped () để kiểm tra xem phương thức này có được gọi cho sự kiện hay không.
Cú pháp
event.stopPropagation()
Parameter | Description |
---|---|
event | Required. The event parameter comes from the event binding function |