Use jQuery's .wrap on all children of a given tag

Viewed 12675

Working jQuery, what I'd like to perform is something similar to the following:

$('sometag').children().wrap('<div></div>');

With the resulting DOM manipulation wrapping all children in one div, not each child individually.

Starting example HTML:

<div>
   <h3>Heading</h3>
   <p>Paragraph</p>
</div>

What this line of code does:

<div>
    <div>
        <h3>Heading</h3>
    </div>
    <div>
        <p>Paragraph</p>
    </div>
</div>

What I want:

<div>
    <div>
        <h3>Heading</h3>
        <p>Paragraph</p>
    </div>
</div>

What is the proper syntax to achieve the end result I'm looking for?

3 Answers
Related