Trying to create a navigation menu with links to each <h2> title on a page : <p>I'm trying to create a navigation menu using jQuery with links to each <code>&lt;h2&gt;</code> title on pages created and published in Wordpress. Some of these pages can get a bit lengthy so this navigation menu should make it quick and easy for visitors to jump to certain parts of it's content.</p>

<p>I've got it set up so that each <code>&lt;h2&gt;</code> title creates it's own unique ID by using it's content prefixed by <strong>"#"</strong> (i.e. <strong>"My title"</strong> would get the ID <strong>"#My title"</strong>) using this piece of code below: </p>

<pre><code>jQuery("h2").each(function(){
      var id = jQuery(this).html();
      jQuery(this).attr("id", "#" + id);
})
</code></pre>

<p>Basically step 1 of 10.. What's left is to create a function that loops trough each <code>&lt;h2&gt;</code> that exists on the page and then creates a menu item for each of those titles. I kind of understand javascript loops but I'm just not sure how to get this to actually create new elements like this.</p>

<p>I'm still a novice when it comes down to Javascript or even jQuery so I apologise if anything's unclear. </p>

<p>Anyways I hope somebody can point me in the right direction. Any help would be much appreciated. </p>
