Open In App

jQuery pushStack() Method

Last Updated : 13 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:




<!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


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




      <!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>

      
      

    • Output:


    Like Article
    Suggest improvement
    Previous
    Next
    Share your thoughts in the comments

    Similar Reads