Here is the structure of my html:
<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>
To retrieve all headings with an ID, I am using this jQuery selector:
var headings = $( ":header[id]" );
My goal is to create a nested list of all these headings in this format:
<ul><li>H1
<ul><li>H2<li>
<li>H2
<ul><li>H3</li></ul>
</li>
</ul>
</li></ul>
I have been struggling to achieve this and couldn't find a solution on Stack Overflow. While I can create a flat list, building a nested one has proven to be more challenging.
If anyone could offer assistance or guidance, I would greatly appreciate it. Thank you!