How to wrap a part of the list?

All will, actually the problem is:
There comes a list, of the form:
the <ul>
<li class="level-0">link #</li>
<li class="level-1">link #</li>
<li class="level-1">link #</li>
<li class="level-2">link #</li>
<li class="level-2">link #</li>
<li class="level-1">link #</li>
<li class="level-0">link #</li>
<li class="level-0">link #</li>
</ul>

where level-0 is the reference zero-level, level-1 first level-2 second.
You need to wrap links of the first and second tag level UL to make multilevel menu:
the <ul>
<li class="level-0">link #</li>
<ul class="sub-menu-1">
 <li class="level-1">link #</li>
 <li class="level-1">link #</li>
 <ul class="sub-menu-2">
 <li class="level-2">link #</li>
 <li class="level-2">link #</li>
</ul>
 <li class="level-1">link #</li>
</ul>
<li class="level-0">link #</li>
<li class="level-0">link #</li>
</ul>

These things can be implemented in jQuery ?
July 8th 19 at 16:18
1 answer
July 8th 19 at 16:20
Take the main list, go to li via .each(function(){});
Inside the function check what the level is(save in a variable) and if it increased, then open the ul tag, if declined then closed(only opening and closing tag have to do to the li tag which is in the current cycle)
thanks, but the problem is that if you insert a via .before part <_ul_> , then the browser closes it. Eventually gets empty UL - tomas.Remp commented on July 8th 19 at 16:23
You can save the Dom elements of the same level in a variable and re-create the whole cascade. - Elyse_Gibson commented on July 8th 19 at 16:26
: Yes, that is the only working version ... - tomas.Remp commented on July 8th 19 at 16:29

Find more questions by tags jQuery