jQuery Methods: pushStack()

By: Dusty Arlia
Published on Sunday, December 15, 2013, 02:06 PM
Last Updated on Saturday, July 11, 2015 at 9:08 PM
Total Updates: 2

The pushStack() jQuery method lets you change the selected elements in a method chain. Pass the elements you would like to select as an array or array-like object to the pushStack() method. These elements become the new selected elements. The previous set of selected elements is pushed on the stack. The end() method can be used to restore them. Here is an example:

var selected_elements = $("h1");   //Select all h1's
selected_elements.pushStack(document.getElementByTagName("div"));   //Select all div's
selected_elements.end()   //Restore all h1's