Event.prototype.stopImmediatePropagation
Prevents other listeners of the same event from being called and stops propagation
Syntax
event.stopImmediatePropagation()Return Value
undefined
Examples
const btn = document.querySelector('button')!
btn.addEventListener('click', (e) => {
console.log('First handler')
e.stopImmediatePropagation()
})
btn.addEventListener('click', () => {
console.log('This will NOT run')
})function addPriorityHandler(el: HTMLElement, handler: (e: Event) => void) {
el.addEventListener('click', (e) => {
handler(e)
e.stopImmediatePropagation()
}, { capture: true })
}const form = document.querySelector('form')!
form.addEventListener('submit', (e) => {
if (!isValid()) {
e.preventDefault()
e.stopImmediatePropagation()
showErrors()
}
})Understanding Event.prototype.stopImmediatePropagation
The Event.prototype.stopImmediatePropagation method in JavaScript prevents other listeners of the same event from being called and stops propagation. It belongs to the Event object and is one of the most widely used methods for working with event values in modern JavaScript and TypeScript applications.
The method signature is event.stopImmediatePropagation(). When called, it returns undefined. Understanding when and how to use stopImmediatePropagation() helps you write more expressive, readable code.
Common use cases for Event.prototype.stopImmediatePropagation include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like event-stoppropagation, event-preventdefault, event-addeventlistener, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Event.prototype.stopImmediatePropagation is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Event.prototype.stopPropagationPrevents further propagation of the current event in the capturing and bubbling phases
Event.prototype.preventDefaultTells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be
EventTarget.prototype.addEventListenerRegisters an event handler of a specific event type on the EventTarget
More Event Methods
Other methods in the Event object
Related Tools
More Event Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.