event.stopPropagation()
event.stopPropagation()
Description: Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
-
version added: 1.0event.stopPropagation()
We can use event.isPropagationStopped()
to determine if this method was ever called (on that event object).
This method works for custom events triggered with trigger(), as well.
Note that this will not prevent other handlers on the same element from running.
Additional Notes:
- Since the
.live()
method handles events once they have propagated to the top of the document, it is not possible to stop propagation of live events. Similarly, events handled by.delegate()
will propagate to the elements to which they are delegated; event handlers bound on any elements below it in the DOM tree will already have been executed by the time the delegated event handler is called. These handlers, therefore, may prevent the delegated handler from triggering by callingevent.stopPropagation()
or returningfalse
.
Example:
Kill the bubbling on the click event.
$("p").click(function(event){
event.stopPropagation();
// do something
});