🔥 $100K Hit! Where Will Bitcoin Go Next? Find Out Live!

Code has been added to clipboard!

Use stopImmediatePropagation to Prevent Event Handlers From Executing

Reading time 1 min
Published Jan 2, 2018
Updated Oct 10, 2019

stopImmediatePropagation: Main Tips

  • This method is used to stop immediate propagation and prevent other event handlers on the same element from executing.
  • It is simply written as event.stopImmediatePropagation() - there are no arguments to include.

event.stopImmediatePropagation Explained

The event.stopImmediatePropagation method doesn't allow other event handlers on the same element to be executed. It can also prevent bubbling up the DOM in the same way as event.stopPropagation method.

Look at the example below. You will see the method preventing the second click event from executing:

Example
$("div").click((event) => {
   alert("Handler 1");
   event.stopImmediatePropagation();
});
$("div").click((event) => {
   alert("Handler 2");
});

Note: check whether the event.stopimmediatepropagation() is applied with the event.isImmediatePropagationStopped method.