Several ways to prevent event bubbling in JQuery and their differences


JQuery provides two ways to prevent events from bubbling.

Method 1: event.stoppropagation ();


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

Method 2: return false;


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

But there is a difference. Return false not only prevents the event from bubbling up, but also prevents the event itself.

Event.stoppropagation () stops the event from bubbling up, not the event itself.