Home > Web Front-end > JS Tutorial > Introduction to several ways to prevent event bubbling in JQuery and their differences_jquery

Introduction to several ways to prevent event bubbling in JQuery and their differences_jquery

WBOY
Release: 2016-05-16 17:03:39
Original
1355 people have browsed it

JQuery provides two ways to prevent events from bubbling.

Method 1: event.stopPropagation();

Copy code The code is as follows:

$("#div1").mousedown(function(event){
event.stopPropagation();
});

Method 2: return false;
Copy code The code is as follows:

$("#div1").mousedown(function(event) {
return false;
});

But there is a difference between these two methods. Returning false not only prevents the event from bubbling up, but also prevents the event itself.

event.stopPropagation() only prevents the event from bubbling up, but does not prevent the event itself.
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template