jquery - finding the last element and not changing it's class
<p>JavaScript and jQuery newbie here, and I wanted to ask a question;
Basically, I have a list and only 1 element of it is displayed at any given time, but the problem is - when I get to the end of the list, and I want to display the next element and hide the current element, than everything becomes hidden. here's the code:</p>

<p>ofcourse that I can set a last element anchor using last(), giving it an ID and then not executing the command if the ID is that of the last element, but I really don't know the syntax for JavaScript to do so.</p>

<p>HTML:</p>

<pre><code>&lt;style&gt;
  #
  #container li .active
  {
    display:inline-block;
  }
  #container li .inactive
  {
    display:none;
  }
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;ul id="container"&gt;
   &lt;il class='active'&gt;item I&lt;/il&gt;
   &lt;il class='inactive'&gt;item II&lt;/il&gt;
   &lt;il class='inactive'&gt;item III&lt;/il&gt;
   &lt;il class='inactive'&gt;item IIII&lt;/il&gt;
   &lt;il class='inactive'&gt;item IV&lt;/il&gt;
   &lt;/ul&gt;
     &lt;span id='next'&gt;Next&lt;/span&gt;
     &lt;span id='prev'&gt;Previous&lt;/span&gt; 

&lt;script&gt;
$(".inactive").hide();
$(".active").show();
$("#next").click(function()
                 {
        var nexte=$(".active");
                nexte.addClass("inactive");
        nexte.removeClass("active")
        nexte.next(".inactive").addClass("active");
        nexte.next(".inactive").removeClass("inactive");
        $(".inactive").hide('slow');
        $(".active").show('slow');
});
$("#prev").click(function()
                 {
        var preve=$(".active");
                preve.addClass("inactive");
        preve.removeClass("active")
        preve.prev(".inactive").addClass("active");
        preve.prev(".inactive").removeClass("inactive");
        $(".inactive").hide('slow');
        $(".active").show('slow');
});
&lt;/script&gt;
</code></pre>

<p>Thanks in advance, itai.</p>
