I have an unordered list that needs to be translated into a hierarchical list, depending on the class that was previously assigned to each
. In particular, if the source list is as follows:<ul>
<li class="level-1"><a href="#">First Level Item</a></li>
<li class="level-2"><a href="#">Second Level item</a></li>
<li class="level-3"><a href="#">Third Level item</a></li>
<li class="level-3"><a href="#">Third Level item</a></li>
<li class="level-2"><a href="#">Second Level item</a></li>
<li class="level-3"><a href="#">Third Level item</a></li>
<li class="level-3"><a href="#">Third Level item</a></li>
<li class="level-3"><a href="#">Third Level item</a></li>
<li class="level-2"><a href="#">Second Level item</a></li>
<li class="level-2"><a href="#">Second Level item</a></li>
<li class="level-1"><a href="#">Next First Level Item</a></li>
<li class="level-2"><a href="#">Second Level item</a></li>
<li class="level-2"><a href="#">Second Level item</a></li>
<li class="level-3"><a href="#">Third Level item</a></li>
<li class="level-3"><a href="#">Third Level item</a></li>
</ul>
I need it to become a nested list based on the class of each li, so the final list is highlighted as:
<ul>
<li class="level-1"><a href="#">First Level Item</a>
<ul>
<li class="level-2"><a href="#">Second Level item</a>
<ul>
<li class="level-3"><a href="#">Third Level item</a></li>
<li class="level-3"><a href="#">Third Level item</a></li>
</ul>
</li>
<li class="level-2"><a href="#">Second Level item</a>
<ul>
<li class="level-3"><a href="#">Third Level item</a></li>
<li class="level-3"><a href="#">Third Level item</a></li>
<li class="level-3"><a href="#">Third Level item</a></li>
</ul>
</li>
<li class="level-2"><a href="#">Second Level item</a></li>
<li class="level-2"><a href="#">Second Level item</a></li>
</ul>
</li>
<li class="level-1"><a href="#">Next First Level Item</a>
<ul>
<li class="level-2"><a href="#">Second Level item</a></li>
<li class="level-2"><a href="#">Second Level item</a>
<ul>
<li class="level-3"><a href="#">Third Level item</a></li>
<li class="level-3"><a href="#">Third Level item</a></li>
</ul>
</li>
</ul>
</ul>
Since I cannot run the server-side code on the CMS that displays this list, I have to reorganize this client side of the HTML list.
, jQuery, . jQuery. , </ul></li> , <ul> , <ul> <li> - , jquery <p> .., </ul></li>?
.wrap, <ul></ul> , , , , , .
- , ?