My html looks like this:
<h1 id="header1">H1</h1>
<p>Lorem ipsum</p>
<h2 id="header2">H2</h2>
<p>lorem ipsum</p>
<h2 id="header3">H2</h2>
<p>lorem upsum</p>
<h3 id="subHeader1">H3</h3>
<p>Lorem Ipsum</p>
I am using the following jquery selector to get all the headings that have an id.
var headings = $( ":header[id]" );
I want to build an nested list of all the headings so that I come up with this:
<ul><li>H1
<ul><li>H2<li>
<li>H2
<ul><li>H3</li></ul>
</li>
</ul>
</li></ul>
I was hoping there was an easy way of accomplishing this. Searched stackoverflow but was not able to find anything. I am able to build a flat list but having trouble building the nested list.
Any help would be extremely appreciated. Thank you!