help building a section nav menu with jquery
<p>I could really use some help with what I have a feeling will be some pretty basic jquery, but I'm stuck all the same.</p>

<p>I have an unknown (dynamically generated) number of divs in my html each with a class of "page".</p>

<p>What I want to do is add an id to each div.page, and then fill a ul with an id of menu with li for each div.page containing an anchor with a href value of #page_n 
(ie the id value of its corresponding div)</p>

<p>I want my output to look like this:</p>

<pre><code>&lt;div class="page" id="page_1"&gt;
...content...
&lt;/div&gt;

&lt;div class="page" id="page_2"&gt;
...content...
&lt;/div&gt;

.....

&lt;div class="page" id="page_n"&gt;
...content...
&lt;/div&gt;


&lt;ul #menu&gt;
    &lt;li&gt;&lt;a href="#page_1"&gt;Page 1&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="#page_2"&gt;Page 2&lt;/a&gt;&lt;/li&gt;
.....
    &lt;li&gt;&lt;a href="#page_n"&gt;Page n&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p>I'm adding the id's okay with:</p>

<pre><code>$('li.page').each(function(index){$(this).attr("id", "page_" + (index+1));
    });
</code></pre>

<p>But I'm struggling with the second part of my problem. I know this is probably kinda basic, but I'm just starting out....</p>

<p>Any help gratefully received... thanks in advance...</p>
