Note that there are some explanatory texts on larger screens.

plurals
  1. PORestructure a single level UL with links into a nested list based on the link urls
    primarykey
    data
    text
    <p>I have a single level unordered list with links to various directory levels. I want to recreate an unordered list from the markup but nesting the list items based on the directory structure of the link URLs.</p> <p>So changing this example:</p> <pre><code>&lt;ul&gt; &lt;li&gt;&lt;a href="/page1"&gt;Page 1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/folder/page2"&gt;Page 2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/folder/page3"&gt;Page 3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>into this:</p> <pre><code>&lt;ul&gt; &lt;li&gt;&lt;a href="/page1"&gt;Page 1&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="/folder/page2"&gt;Page 2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/folder/page3"&gt;Page 3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I have a jsfiddle work-in-progress which is compiled based on two similar stackoverflow questions, but I can't get it working.</p> <p><a href="http://jsfiddle.net/logopogo/q6H7e/1/" rel="nofollow noreferrer">http://jsfiddle.net/logopogo/q6H7e/1/</a></p> <p>My current line of thought is to convert the single level list into javascript data (JSON ?) using the answer from here: <a href="https://stackoverflow.com/questions/1837383/how-do-i-convert-the-items-of-an-li-into-a-json-object-using-jquery">How do I convert the items of an LI into a json object using jquery?</a></p> <p>Then reconstruct a new list from that JSON data using the answer from here: <a href="https://stackoverflow.com/questions/7133657/create-a-nested-ul-menu-based-on-the-url-path-structure-of-menu-items">Create a nested UL menu based on the URL path structure of menu items</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload