How to prevent event bubbling in JQuery and its difference

How to prevent event bubbling in JQuery and its difference

Method 1: event.stopPropagation();

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

Method 2: return false;

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

But the two ways are different.
return false not only stops the event from bubbling up, but also the event itself.
event.stopPropagation() only stops the event from bubbling up, not the event itself.

$("#div1").keydown(function (e) {
            if (e.keyCode == 13 || e.keyCode == 108) {
                e.stopPropagation();
            }
        })

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325814526&siteId=291194637