How to find with javascript the current page in a <ul> tree
<p>I am trying to create dynamic next and previous buttons with javascript.  I am stuck at the point of trying to create a variable that describes the current page I am on, relative to a ul tree.</p>

<p>I have looked at </p>

<pre><code>    window.location;
</code></pre>

<p>But after returning the full url, I am stuck at striping this string down to just the x.html and then finding this in the li links.</p>

<p>After finding an li link in my ul tree I can generate the next and previous links using children as in this fiddle: <a href="http://jsfiddle.net/JyfS2/" rel="nofollow">http://jsfiddle.net/JyfS2/</a></p>

<p>Example code - If I am on page b, find this page, and make the PREV link link to a.html, and the NEXT to c.html</p>

<pre><code>&lt;ul&gt;
    &lt;li id="1"&gt;&lt;a href="a.html"&gt;a&lt;/a&gt;&lt;/li&gt;
    &lt;li id="2"&gt;&lt;a href="b.html/"&gt;b&lt;/a&gt;&lt;/li&gt;
    &lt;li id="3"&gt;&lt;a href="c.html"&gt;c&lt;/a&gt;&lt;/li&gt;
     &lt;/ul&gt;
&lt;div&gt;
&lt;a id="next" href=""&gt;next&lt;/a&gt;
&lt;a id="prev" href=""&gt;prev&lt;/a&gt;
&lt;/div&gt;
</code></pre>

<p>Some JS I have been using - So I would want to replace $('li#2') with a variable that describes the current page:</p>

<pre><code>    &lt;script&gt;
        var next_url = $('li#2').next()[0].firstChild.href;
        var prev_url = $('li#2').prev()[0].firstChild.href;
        var loc = window.location;
        alert(loc);
        document.getElementById('next').href = next_url;
        document.getElementById('prev').href = prev_url;

&lt;/script&gt;
</code></pre>
