jQuery Multiple Event Handlers – How to Cancel?

Use the stopImmediatePropagation function of the jQuery event object.

Keeps the rest of the handlers from being executed.
This method also stops the bubbling by calling event.stopPropagation().

$(document).click(function(event) { 
  alert('a');
  event.stopImmediatePropagation();
  return false;
});

$(document).click(function() {
  alert('b');
});

Leave a Comment