title: Is there a JavaScript solution to generating a "table of contents" for a page?
body: <p>I have headers in <code>&lt;h1&gt;</code> through <code>&lt;h6&gt;</code> tags. Is there a way that I can use JavaScript to generate a table of contents for the contents that serves as anchor tags as well?</p>
  
  <p>I would like the output to be something like:</p>
  
  <pre><code>&lt;ol&gt;
      &lt;li&gt;Header 1&lt;/li&gt;
      &lt;li&gt;Header 1&lt;/li&gt;
          &lt;li&gt;Header 2&lt;/li&gt;
              &lt;li&gt;Header 3&lt;/li&gt;
  &lt;/ol&gt;
  </code></pre>
  
  <p>I am not currently using a JavaScript framework, but I don't see why I couldn't use one.</p>
  
  <p>I am also looking for something done, since I'm guessing this is a common problem, but if not, a starting point to roll my own would be good.</p>