TheNone
TheNone

Reputation: 5802

Set apart items of UL and wrap them into another tags

I have a list such this:

<ul class='as-selections'>
    <li class='as-selection-item'> item1 </li>
    <li class='as-selection-item'> item2 </li>
    <li class='as-selection-item'> item3 </li>
    <li class='as-orjinal'> item3 </li>
</ul>

How can I group all items with as-selection-item class and wrap them in <li class="thelist"><ul></ul></li> ?

Thanks in advance

Upvotes: 0

Views: 57

Answers (1)

adeneo
adeneo

Reputation: 318182

You can use wrapAll :

$('.as-selection-item').wrapAll('<li><ul></ul></li>');

FIDDLE

If you have more than one list, you'll have to iterate:

$('.as-selections').each(function(i, ul) {
    $('.as-selection-item', ul).wrapAll('<li><ul></ul></li>');
});

Upvotes: 4

Related Questions