Encapsulate a set of divs with another div in jQuery

Posted by lafoaug on Stack Overflow See other posts from Stack Overflow or by lafoaug
Published on 2010-06-10T10:09:21Z Indexed on 2010/06/10 10:12 UTC
Read the original article Hit count: 178

Filed under:
|
|

Hi,

I am a little stumped with how to do this.

I am using jQuery and wish to encapsulate certain sets of divs with a div.

For example I have:

<div class="group-1">x</div>
<div class="group-1">x</div>
<div class="group-2">x</div>
<div class="group-2">x</div>
<div class="group-3">x</div>

And wish to end up with:

<div id="set-1">
<div class="group-1">x</div>
<div class="group-1">x</div>
</div>
<div id="set-2">
<div class="group-2">x</div>
<div class="group-2">x</div>
</div>
<div id="set-3">
<div class="group-3">x</div>
</div>

I am able to cycle through each div and add a div around each one but not the way I want above. Any advice appreciate.

Thanks.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery