stopImmediatePropagation() Event Method - Javascript DOM

Javascript examples for DOM:Event

Description

The stopImmediatePropagation() method can stop other listeners of the same event.

Parameters

None

Return Value

No return value

When clicking on a button, execute the first event handler, and stop the rest of the event handlers.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button id="myBtn">Test</button>

<script>
function myFunction(event) {/* ww w  . j  a v  a 2  s .  co  m*/
    console.log("Hello World!");
    event.stopImmediatePropagation();
}

function someOtherFunction() {
    console.log("I will not get to say Hello World");
}

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

</body>
</html>

Related Tutorials