(jQuery) How to catch two divs and insert them on a new div

advertisements

I'm very newbie with jQuery (and Javascript) and i don't know how to do this.

I want to grab two divs and insert them on a new div.

Example:

 <div class="test"></div>
 <div class="test"></div>
 <div class="test2"></div>
 <div class="test2"></div>

to

<div class="float">
    <div class="test"></div>
    <div class="test"></div>
</div>

<div class="test2"></div>
<div class="test2"></div>

Thank you very much


Use wrapAll.

 $('div.test').wrapAll( "<div class='float'></div>" );