event.stopPropagation() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:event.stopPropagation


The event.stopPropagation() method stops the event bubbling to parent elements.


Parameter Require Description
event Required.The event parameter comes from the event binding function

The following code shows how to Stop the click event from bubbling to parent elements:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        event.stopPropagation();/*from   ww  w  .j a va 2s . com*/
        console.log("The span element was clicked.");
        console.log("The p element was clicked.");
        console.log("The div element was clicked.");

<div style="height:100px;width:500px;padding:10px;border:1px solid blue;background-color:red;">
This is a div element.
<p style="background-color:pink">This is a p element, in the div element.
<br><span style="background-color:orange">This is a span element in the p and the div element.</span></p>


Related Tutorials