stopImmediatePropagation() Event Method

Example

When clicking on a button, execute the first event handler, and stop the rest of the event handlers from being executed:

var x = document.getElementById("myBtn");
x.addEventListener("click", myFunction);
x.addEventListener("click", someOtherFunction);

function myFunction(event) {
  alert ("Hello World!");
  event.stopImmediatePropagation();
}

// This function will not be executed
function someOtherFunction() {
  alert ("I will not get to say Hello World");
}
Try it Yourself »

Description

The stopImmediatePropagation() method prevents other listeners of the same event from being called.


Browser Support

The numbers in the table specify the first browser version that fully supports the method.

Method
stopImmediatePropagation() Yes 9.0 Yes Yes Yes

Syntax

event.stopImmediatePropagation()

Parameters

None

Technical Details

Return Value: No return value
DOM Version: DOM Level 3 Events

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.