.pushStack(elements) builds a new jQuery object from an array of DOM nodes and pushes it onto the internal selection stack (same API as api.jquery.com/pushStack). This tutorial covers the official demo, pairing with .end(), plugin patterns, the optional name/arguments form, five examples, and try-it labs.
01
Push set
From array
02
Stack
Keep previous
03
.end()
Pop back
04
Plugins
Custom traversal
05
name / args
Since 1.3
06
Since 1.0
Core API
Fundamentals
Introduction
When you call .find() or .filter(), jQuery does not throw away the previous match — it keeps a stack of selections so .end() can walk back. That push behavior is exposed as .pushStack().
Since jQuery 1.0, .pushStack(elements) lets you take any array-like list of DOM nodes, wrap them as the current jQuery set, and still recover the earlier set with .end(). Plugin authors use it so custom methods feel like built-in traversal.
You rarely need .pushStack() in app UI code — prefer .find(), .filter(), and .end(). Learn it to understand the stack and to write chain-friendly plugins. See the Traversing hub.
Concept
Understanding the .pushStack() Method
Call .pushStack(elements) on a jQuery object and pass an array (or array-like collection) of DOM elements. jQuery creates a new collection from those nodes and remembers the previous collection on an internal stack.
The official demo starts from an empty set, pushes every <div> on the page, removes them, then .end() returns to the empty starter set.
💡
Beginner Tip
Think of .pushStack() as “make this array the current selection, but remember where I was.” .end() is “go back one memory.”
All <div> elements removed from the document
.after .end() the chain is back on the empty starter set
How It Works
getElementsByTagName returns a live HTMLCollection; jQuery accepts it as the elements array. .remove() acts on the pushed set; .end() restores jQuery([]).
Example 2 — Style Pushed Nodes, Then End
Push specific elements, change CSS, return to the previous selection.
Returning $(els) from a plugin without pushStack breaks .end() expectations.
Primarily an internals / plugin API — intermediate topic for learners.
Compatibility
Browser Support
.pushStack() has been part of jQuery since 1.0+. It works in every browser supported by your jQuery build — including modern evergreen browsers with jQuery 3.x. Stack behavior is implemented by jQuery.
✓ jQuery 1.0+
.pushStack()
Stable selection-stack helper used by plugins and built-in traversal methods.
100%With jQuery 1.0+
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.pushStack()1.0+
Bottom line: Use in plugins that return a new set; prefer .find()/.filter() in app code.
Wrap Up
Conclusion
.pushStack() pushes a new array of DOM elements onto jQuery’s selection stack so .end() can restore the previous set. It is the building block behind friendly chaining in plugins and custom traversal helpers.
Next up: .eq() to reduce a set to a single element by index.
Return this.pushStack(matched) from custom traversal plugins
Pass a real array of DOM nodes (.get() / Array.from)
Document that callers can use .end() after your method
Prefer .find() / .filter() when selectors are enough
Test chains that mix your method with .end()
❌ Don’t
Pass a selector string where an elements array is required
Return a disconnected $(els) if you want .end() support
Use pushStack for simple app chaining when built-ins suffice
Forget that pushed elements are the current set until .end()
Confuse pushStack with .add() (merge vs replace+stack)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .pushStack()
The selection-stack push used by plugins and internals.
5
Core concepts
↑01
Pushes
New set
Array
☰02
Keeps
Previous
Stack
←03
Pair
.end()
Pop
⚙04
For
Plugins
Custom
1.005
Since
1.0
API
❓ Frequently Asked Questions
.pushStack(elements) takes an array of DOM elements, wraps them in a new jQuery object, and pushes that object onto jQuery’s internal selection stack. The previous set is preserved so a later .end() can restore it. Available since jQuery 1.0.
Mostly plugin and library authors who build custom traversal methods. Everyday code usually uses .find(), .filter(), .add(), and .end() — those already manage the stack for you. Learn .pushStack() so custom methods can support .end() correctly.
.pushStack() pushes a new set. .end() pops one level and returns the previous set. The official demo pushes all divs, calls .remove(), then .end() to leave the earlier (empty) set. Without pushStack, a custom set would not be reversible with .end().
Since jQuery 1.3 you can pass .pushStack(elements, name, args) where name is the method that produced the elements and args is the argument list used for serialization / debugging. Day-to-day plugins often use the simple .pushStack(elements) form.
.add() merges extra elements into the current selection (or starts from them). .pushStack() replaces the current matched set with a new jQuery object built from an array, while stacking the old set for .end(). They solve different problems.
A new jQuery object containing the elements you passed. You can chain methods on it like any other collection.
Did you know?
Many of jQuery’s own traversal methods are thin wrappers around collecting nodes and calling the same stack machinery that .pushStack() exposes. When $("ul").find("li").end() works, you are using the same idea the official empty-set + getElementsByTagName demo shows in the open.