Event

Event.prototype.stopPropagation

Prevents further propagation of the current event in the capturing and bubbling phases

Syntax

JavaScript
event.stopPropagation()

Return Value

undefined

Examples

Basic Usage
document.querySelector('.child')!.addEventListener('click', (e) => {
  e.stopPropagation()
  console.log('Child clicked, parent will not receive this event')
})
Practical Example
const modal = document.querySelector('.modal')!
modal.addEventListener('click', (e) => {
  e.stopPropagation()
})
document.addEventListener('click', () => {
  console.log('This runs only for clicks outside modal')
})
Advanced Usage
function createIsolatedHandler(el: HTMLElement, handler: (e: Event) => void) {
  el.addEventListener('click', (e) => {
    e.stopPropagation()
    handler(e)
  })
}

Understanding Event.prototype.stopPropagation

The Event.prototype.stopPropagation method in JavaScript prevents further propagation of the current event in the capturing and bubbling phases. 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.stopPropagation(). When called, it returns undefined. Understanding when and how to use stopPropagation() helps you write more expressive, readable code.

Common use cases for Event.prototype.stopPropagation include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like event-preventdefault, event-stopimmediatepropagation, event-addeventlistener, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Event.prototype.stopPropagation 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

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.