 <p>Add a variable that keeps track of the current slide. </p> <pre><code>$("document").ready(function(){ var counter = 1; $("#back").click(function() { if( counter &gt; 1 ) { $("#gallery").animate({"left": "+=104px"}, "slow"); counter--; } }); $("#forward").click(function(){ if( counter &lt; 4 ) { $("#gallery").animate({"left": "-=104px"}, "slow"); counter++; } }); }); </code></pre>