Select the group, then pass one wrapper structure.
Select the elements that should share one parent.
Pass HTML, a DOM element, a jQuery object, or a selector as the wrapper.
Or pass a function (1.4+) that returns the wrapper (once in jQuery 3+).
Keep only one innermost element in nested wrapper HTML.
Piece
Required?
Role
Matched set
Yes
Elements grouped under one parent
wrappingElement
Yes*
HTML / element / jQuery / selector
function
Alt (1.4+)
Returns wrapper; this = first match (3.0+)
Pseudocode
Pseudocode
if argument is a function:
wrapper = function.call(firstMatchedElement)
else:
wrapper = clone(wrappingElement) // templates are cloned, not moved
insert wrapper before the first matched element
move all matched elements into the innermost wrapper node
// non-matched siblings between them stay outside
return original matched set
Reference
Cheat Sheet
Keep these facts handy while grouping nodes.
Topic
Detail
Since
jQuery 1.2 (callback 1.4)
Result
One shared parent for the whole set
vs wrap
.wrap() = one parent each
Gaps
Non-matched siblings stay outside
Templates
jQuery/DOM templates are cloned
Return
Original matched set
Inverse
.unwrap() on the children
Try it
Live Preview
Wrap all sample paragraphs in one parent, or reset.
Browser demo of .wrapAll() — same idea as the examples below.
Hello
cruel
World
Result
Ready — pick an action and Run
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Original stays. The template node is not relocated.
Group. Matched paragraphs sit inside the clone.
Edge Cases & Pitfalls
Check these before grouping large selections.
gaps
In-between siblings are excluded
Only matched elements move into the wrapper. Text or nodes between them stay outside.
clone
jQuery templates are cloned
Passing $(".box") does not move that node — a clone wraps the set.
nest
One innermost element
Nested wrapper HTML is fine, but there must be a single deepest container for the matches.
xss
Untrusted HTML is unsafe
Do not build wrapper strings from URL params, cookies, or form fields without escaping.
Compatibility
Browser Support
.wrapAll() has been part of jQuery since 1.2. The function callback arrived in 1.4; jQuery 3.0 fixed it to run once for the set.
✓ Stable · jQuery 1.2+
jQuery .wrapAll()
Supported in all browsers that run jQuery 1.2+. Prefer a current jQuery 3.x build for modern projects.
100%jQuery core method
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
.wrapAll()Universal
Bottom line: Use when the whole selection should share one parent. Prefer .wrap() when each match needs its own.
Analysis
Performance Notes
Approach
Cost
Best for
Small set + one wrapAll
Cheap
Grouping a short list
Deep nested wrapper HTML
Moderate
Occasional layout shells
Huge selections often
Expensive
Avoid — restructure less often
One shared wrapper is cheaper than wrapping each node separately with .wrap() when you only need a single group container.
Remember
Key Takeaways
Role: one shared parent for the entire matched set.
vs wrap:.wrap() = parent per element.
Gaps: non-matched siblings stay outside the group.
Undo:.unwrap() removes the shared parent.
One line:.wrapAll() puts the whole selection under one parent — use it when you need a group container, not per-item wrappers.
Frequently Asked Questions
.wrapAll() wraps all matched elements together in one shared parent structure. Returns the original matched set. Available since jQuery 1.2; callback form since 1.4.
.wrap() gives each match its own parent. .wrapAll() puts the whole set inside one shared parent.
.wrapAll() wraps the matched elements themselves. .wrapInner() wraps the contents inside each matched element.
Non-matched nodes between selected elements are left out of the wrapper. Only the matched set is grouped.
No. When you pass a jQuery object or DOM node as the wrapper template, jQuery clones that structure. The original stays put.
Yes, since 1.4. In jQuery 3.0+, the callback runs once with this set to the first matched element and should return HTML or a jQuery object.
Call .unwrap() on the wrapped children to remove the shared parent and leave them in place.