Logical problem with list order
<p>I think i kind off miss some logical insight. It seems so easy, but i just don't see it..</p>

<p>I have a list and want to see if there are list items before and/or after the clicked item. Here's the code</p>

<pre><code>
&lt;script&gt;
[..]
$("a").click(function(event){
 var parentEl = $(this).closest("ul");
 var currPosition = $(this).parent().prevAll().length + 1;
 var totalItems = $("#"+$(parentEl).attr("id")+" li").length;

 if(currPosition == totalItems){ alert("Previous and Next"); }
 if(currPosition &lt;= totalItems){ alert("Next"); }
 if(currPosition &gt;= totalItems){ alert("Previous"); } 
[..]
&lt;/script&gt;

[..]

&lt;ul id="listOne"&gt;
 &lt;li&gt;&lt;a&gt;Text 1&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a&gt;Text 2&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a&gt;Text 3&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a&gt;Text 4&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p>The code above almost works only one i click the last item, everything gets alerted..
I just want to know if there is a previous, next or both opions on the list-items that's clicked</p>
