In the browser, stopPropagation() and stopImmediatePropagation() are not the same

published Dec 06, 2018 12:45   by admin ( last modified Dec 06, 2018 12:45 )

In fact stopImmediatePropagation stops more stuff, also any event handlers on the element you're calling it for, not just parent elements.

In the MDN documentation for preventDefault(), you can read this:

The event continues to propagate as usual, unless one of its event listeners calls stopPropagation() or stopImmediatePropagation(), either of which terminates propagation at once.

This can give you the impression that they are equal, which they are not. I just got out of a sticky bind by using stopImmediatePropagation() instead of stopPropagation(). Still  not sure as to why, but suspect it may have to do with promise chains, that were called on the line after the preventDefault() handler.