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.