それぞれに事前に割り当てられたクラスに応じて、階層リストに分割する必要がある順序付けられていないリストがあります
<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>
各 li のクラスに基づいてネストされたリストになる必要があるため、最終的なリストは次のように変更されます。
<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>
このリストを出力している CMS でサーバー側のコードを実行できないため、この HTML リストのクライアント側を再編成する必要があります。
新しい階層を作成するために独自の jQuery を作成しようとして、何時間も費やしました。私の最初の試みは、jQuery .before を使用し</ul></li>
てクラスの前に追加のタグを追加し、タグの後に新しいタグを追加しようとしましたが、挿入されたタグ<ul>
を取得できませんでした-jquery はなどを追加するようですが、ではありませんか?<ul> <li>
<p>
</ul></li>
次に、 .wrap を使用して<ul></ul>
必要な場所に新しいものを配置しようとしましたが、すべての子または孫を選択してグループ化してラップする方法を理解するほど賢くありませんでした。
私がやろうとしていることについて何かヒントはありますか?