jQuery | die() Method

The die() method added with live() method, removes one or more event handlers, for selected elements.

Syntax:

$(selector).die(event, function) 

Parameter:

  • event: Specifies one or more than one event handlers to remove. Multiple valid event values are separated by space.
  • function: It is used to specify a function to be removed.

Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <script src=
    </script>
    <script>
        function changeSize() {
            $(this).animate({
                fontSize: "+=3px"
            });
        }
  
        function changeSpacing() {
            $(this).animate({
                letterSpacing: "+=2px"
            });
        }
  
        $(document).ready(function() {
            $("p").live("click", changeSize);
            $("p").live("click", changeSpacing);
            $("button").click(function() {
                $("p").die("click", changeSize);
            });
        });
    </script>
</head>
  
<body>
  
    <center>
        <p style="color:green;">
          Geeks for geeks.
      </p>
        <button>
          added with the live() method, 
          Remove the event handler changeSize(), 
          for p elements
      </button>
    </center>
</body>
  
</html>

chevron_right


Output:

Before clicking on the paragraph:

After clicking on the paragraph:

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <script src=
    </script>
    <script>
        function changeSize() {
            $(this).animate({
                fontSize: "+=3px"
            });
        }
  
        function changeSpacing() {
            $(this).animate({
                letterSpacing: "+=2px"
            });
        }
  
        $(document).ready(function() {
            $("h1").live("click", changeSize);
            $("h1").live("click", changeSpacing);
            $("button").click(function() {
                $("h1").die("click", changeSize);
            });
        });
    </script>
</head>
  
<body>
    <div>
        <center>
            <h1>welcome to GFG</h1>
      </center>
    </div>
  
    <center>
        <button>click here</button>
    </center>
</body>
  
</html>

chevron_right


Before clicking on the paragraph:

After clicking on the paragraph:



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.