Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Wrap elements after one div and before anotherone

Tags:

html

jquery

I have this html

<div class="sbox">
<div class="top-sbox"></div>
<h3>Menu</h3>
    <ul class="subpages">
    <li><a href="#">Subpagina</a></li>
    <li><a href="#">Subpagina</a></li>
    <li><a href="#">Subpagina</a></li>
    <li><a href="#">Subpagina</a></li>
    <li><a href="#">Subpagina</a></li>
    <li><a href="#" class="last">Subpagina</a></li>
    </ul>


<div class="bottom-sbox"></div>
</div>

How can I wrap all elements after div.top-sbox and before div.bottom-sbox. Thank you!

I want this result:

<div class="sbox">
<div class="top-sbox"></div>
<div id="wrapper">
<h3>Menu</h3>
    <ul class="subpages">
    <li><a href="#">Subpagina</a></li>
    <li><a href="#">Subpagina</a></li>
    <li><a href="#">Subpagina</a></li>
    <li><a href="#">Subpagina</a></li>
    <li><a href="#">Subpagina</a></li>
    <li><a href="#" class="last">Subpagina</a></li>
    </ul>
</div>  
<div class="bottom-sbox"></div>
</div>
like image 448
Adrian Florescu Avatar asked May 10 '11 00:05

Adrian Florescu


1 Answers

Here you are.

Edit: sorry. Even simpler: http://jsfiddle.net/ajRd2/1/

$('.top-sbox').nextUntil('.bottom-sbox').wrapAll('<div class="dwrap" />'); 
like image 139
wesbos Avatar answered Oct 21 '22 03:10

wesbos