jQuery pushStack() Method

The pushStack() method in jQuery is used to add a collection of DOM elements onto the jQuery stack.

Syntax:

.pushStack(elements, name, arguments)

Parameters:

  • elements: This is the array of elements to be pushed onto the stack and make into a new jQuery object.
  • name: This argument defines the name of a jQuery method which has generated the array of elements.
  • arguments: The argument that were passed in to the jQuery method for serialization.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE HTML>
<html>
  
<head>
    <title>
        JQuery pushStack() method
    </title>
  
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
      
    <p>
        JQuery | pushStack() method
    </p>
  
    <div
        This is div
    </div>
    <br>
  
    <button onclick="Geeks()">
        Click here
    </button>
      
    <p id="GFG"></p>
  
    <script>
        var el_down = document.getElementById("GFG");
  
        function Geeks() {
            jQuery([]).pushStack(
                document.getElementsByTagName("div"))
                .remove().end();
  
            el_down.innerHTML
                = "The DOM element <div> has "
                    + "been pushed to stack and then"
                    + " removed.";
        
    </script>
</body>
  
</html

chevron_right


  • Output:
    • Example 2: This example checked the odd indexed checkboxes.

      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      <!DOCTYPE HTML>
      <html>
        
      <head>
          <title>
              JQuery pushStack() method
          </title>
        
          <script src=
          </script>
      </head>
        
      <body style="text-align:center;">
        
          <h1 style="color:green;">
              GeeksForGeeks
          </h1>
            
          <p>JQuery | pushStack() method</p>
        
          <div>This is div</div>
          <br>
        
          <button onclick="Geeks()">
              Click here
          </button>
            
          <div id="GFG"></div>
        
          <script>
        
              var el_down = document.getElementById("GFG");
        
              function Geeks() {
                  jQuery([]).pushStack(
                      document.getElementsByTagName("p"))
                      .remove().end();
        
                  el_down.innerHTML = "The DOM element "
                      + "<p> containing 'JQuery |"
                      + " pushStack() method has been "
                      + "pushed to stack and then removed.";
              
          </script>
      </body>
        
      </html>

      chevron_right

      
      

    • Output:



    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.