Corentin Branquet
Corentin Branquet

Reputation: 1576

Wrap divs from div parent

I have this code

<div class="superdiv">
  <div></div>
  <div></div>
</div>

I want to wrap all .superdiv children divs into a div called <div class="subdiv"></div>

How can I make that ?

Thanks

Upvotes: 1

Views: 26

Answers (2)

Nikhil Aggarwal
Nikhil Aggarwal

Reputation: 28445

Try following

$(".superdiv > div").wrapAll("<div class='subdiv'/>");

Upvotes: 0

Josh Crozier
Josh Crozier

Reputation: 240868

You could use the .wrapInner() method:

$('.superdiv').wrapInner('<div class="subdiv"></div>');

You could also use the .wrapAll() method on the children elements:

$('.superdiv').children().wrapAll('<div class="subdiv"></div>');

Upvotes: 2

Related Questions