.pushStack(elements) (since jQuery 1.0) builds a new jQuery object from an array of DOM elements and pushes it onto the selection stack. The previous set stays available for .end().
Remember
// Official pattern
jQuery([])
.pushStack(document.getElementsByTagName("div"))
.remove()
.end();
// Plugin idea — custom set + reversible with .end()
return this.pushStack(matchedElements);
// Since 1.3 (optional metadata)
.pushStack(elements, "myMethod", [arg1, arg2]);
Name / args. Optional metadata for serialization (since 1.3).
Behavior. The active set still contains the three boxes.
Daily use. Most plugins can omit name/args and pass elements only.
Edge Cases & Pitfalls
Check these before using .pushStack() in app code.
audience
Not for everyday selection
Prefer .find() / .filter() / .add(). Reach for .pushStack() when you write a custom method that must support .end().
input
Pass DOM elements, not a selector string
.pushStack("div") is wrong. Pass an array or array-like list of nodes (e.g. from .get() or querySelectorAll).
wrap
$(array) is not the same
Wrapping with $() does not stack the previous set. Without .pushStack(), .end() will not return to your prior collection.
end
Remember to .end() in demos
If you push and mutate, call .end() when the chain should continue on the previous set — just like the official example.
Compatibility
Browser Support
.pushStack() is a core jQuery method since 1.0 (name/arguments overload since 1.3). It works in every browser that runs your loaded jQuery version.
✓ Stable · jQuery 1.0+
jQuery .pushStack()
Universal across jQuery-supported browsers. Mainly used inside plugins that need reversible custom sets.
1.0+jQuery since
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()Universal
Bottom line: Safe and stable. Learn it for plugin authoring; prefer built-in traversal for normal pages.
Analysis
Performance Notes
Approach
Cost
Best for
.find() / .filter()
Cheapest habit
Everyday traversal (already stacked)
.pushStack(smallArray)
Cheap
Plugin return values
Huge node lists repeatedly
Moderate
Avoid building giant arrays needlessly
The stack link itself is cheap. Cost comes from collecting and operating on large element arrays — keep plugin results focused.
Remember
Key Takeaways
Role: push a new element array onto the selection stack.
Pair: use with .end() to restore the previous set.
Audience: plugin authors more than day-to-day page scripts.
vs .add(): replace+stack vs merge into the current set.
One line:.pushStack() makes a custom element array a proper jQuery chain step so .end() can undo it.
Frequently Asked Questions
.pushStack(elements) wraps an array of DOM elements in a new jQuery object and pushes it onto jQuery’s internal selection stack. The previous set is kept 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. Learn .pushStack() so custom methods can support .end() correctly.
.pushStack() pushes a new set. .end() pops one level and returns the previous set. Without .pushStack(), a hand-built collection may 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 for serialization. Day-to-day plugins often use the simple .pushStack(elements) form.
.add() merges extra elements into the current selection. .pushStack() replaces the current matched set with a new jQuery object from an array, while stacking the old set for .end().
A new jQuery object containing the elements you passed. You can chain methods on it like any other collection.