jQuery | event.stopImmediatePropagation() Method

The event.stopImmediatePropagation() is an inbuilt method in jQuery used to stop the rest of the event handlers from being executed for the selected element.

Syntax:

event.stopImmediatePropagation()

Parameter: No parameter is required.



Return Value: This method return the selected element with the applied change.

Example-1: Here, only first pop box will appear after the this method will stop the other pop box to appear.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <script src=
  </script>
    <style>
        body {
            width: 70%;
            height: 40%;
            font-size: 30px;
            padding: 20px;
            border: 2px solid green;
        }
          
        div {
            display: block;
            background-color: lightgrey;
            padding: 4px;
        }
    </style>
    
    <script>
        $(document).ready(function() {
            $("div").click(function(event) {
                alert("1st event executed");
                event.stopImmediatePropagation();
            });
            $("div").click(function(event) {
                alert("2nd event executed");
            });
            $("div").click(function(event) {
                alert("3rd event executed");
            });
        });
    </script>
</head>
  
<body>
  
    <div>Hello, Welcome to GeeksforGeeks.!</div>
  
</body>
  
</html>

chevron_right


Output :

Before click:

After click:

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html lang="en">
  
<head>
    <script src=
  </script>
    <style>
        body {
            width: 70%;
            height: 40%;
            font-size: 30px;
            padding: 20px;
            border: 2px solid green;
        }
          
        p {
            display: block;
            padding: 4px;
            height: 30px;
            width: 150px;
            background-color: lightgrey;
        }
          
        div {
            display: block;
            padding: 4px;
            height: 30px;
            width: 400px;
            background-color: lightgrey;
        }
    </style>
  
</head>
  
<body>
  
    <p>Hello, </p>
    <div>Welcome to GeeksforGeeks.!</div>
  
    <script>
        $("p").click(function(event) {
            event.stopImmediatePropagation();
        });
        $("p").click(function(event) {
            // This function will not executed
            $(this).css("background-color", "yellow");
        });
        $("div").click(function(event) {
            // This function will executed
            $(this).css("background-color", "green");
        });
    </script>
</body>
  
</html>

chevron_right


Output:
Before click:

After click on the “p” and “div” element. Event will only perform for the div element:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.