title: Disable Carousel Prev Next buttons
body: <p>Hello I need to disable Previous and Next anchors in the following script if it show first and last div respectively. Here is the <a href="http://jsfiddle.net/vHC4X/3/" rel="nofollow">fiddle</a> for it.
  I have several anchors which shows the corresponding div when clicked. I also have Previous and next anchors which when clicked go to next and previous divs respectively.</p>
  
  <p>I am looking to disable "Prev" in case it is showing the first div ie div0 and to disable "Next" in case it is showing the last div ie div4. Also please let me know if the code is broken somewhere.
  Thanks</p>
  
  <pre><code>    &lt;a class="prev"&gt;prev&lt;/a&gt;  &amp;nbsp;
      &lt;a class="next"&gt;next&lt;/a&gt;
      &lt;a class="anc" id="an0"&gt;A1&lt;/a&gt;
      &lt;a class="anc" id="an1"&gt;A2&lt;/a&gt;
      &lt;a class="anc" id="an2"&gt;A3&lt;/a&gt;
      &lt;a class="anc" id="an3"&gt;A4&lt;/a&gt;
      &lt;a class="anc" id="an4"&gt;A5&lt;/a&gt;
  
  
  
      &lt;div class="zdivs"&gt;
              &lt;div id="q0" class="hidepiece"&gt;
                  Lorem ipsum dolor sit amet
              &lt;/div&gt;
              &lt;div id="q1" class="hidepiece"&gt;
                   consectetuer adipiscing elit
              &lt;/div&gt;
              &lt;div id="q2" class="hidepiece"&gt;
                  sed diam nonummy nibh euismod tincidunt 
              &lt;/div&gt;
              &lt;div id="q3" class="hidepiece"&gt;
                  laoreet dolore magna aliquam erat volutpat
              &lt;/div&gt;
              &lt;div id="q4" class="hidepiece"&gt;
                  Ut wisi enim ad minim veniam
              &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>And here is the jQuery for hiding all divs with class name 'hidepiece' and show them one by one on clicking anchors </p>
  
  <pre><code>&lt;!--One by one navigation class anc hidepiece--&gt;
  &lt;script&gt;
  $(document).ready(function() {
  $("div.hidepiece").hide();
  $("a.anc").click(function() {
      var id = $(this).attr("id");
      var divId = id.replace("an", "q");
      $("div.hidepiece").hide();
      $("div#" + divId).fadeIn("slow");
      $("#zdivs").scrollTop(0);//scrolls zdiv to top
    });
  });
  &lt;/script&gt;
  
  &lt;!--previous next class zdivs--&gt;
  &lt;script&gt;
  $(document).ready(function(){
  $(".zdivs div").each(function(e) {
      if (e != 0)
          $(this).hide();
  });
  
  $(".next").click(function(){
    $("#zdivs").scrollTop(0);
      if ($(".zdivs div:visible").next().length != 0)
          $(".zdivs div:visible").next().fadeIn("slow").prev().hide();
      else {
          $(".zdivs div:visible").hide();
          $(".zdivs div:first").fadeIn("slow");
      }
      return false;
  });
  
  $(".prev").click(function(){
    $("#zdivs").scrollTop(0);
      if ($(".zdivs div:visible").prev().length != 0)
          $(".zdivs div:visible").prev().fadeIn("slow").next().hide();
      else {
          $(".zdivs div:visible").hide();
          $(".zdivs div:last").fadeIn("slow");
      }
      return false;
    });
  });
  &lt;/script&gt;
  </code></pre>