Loop with trigger (which contains animation) not working <p>So I seem to have run into a bit of a dead end. I'm making a page which has an image slider. The slider has three images, one centered on the screen, the other two overflow on the left and right. When you click on the button to advance the slides it runs this code.... </p> <pre><code>$('#slideRight').click(function() { if ($('.container').is(':animated')) {return false;} var next=parseInt($('.container img:last-of-type').attr('id')) + 1; if (next == 12) { next = 0; } var diff = galsize() - 700; if ($('.thumbs').css("left") == "0px") { var plus = 78; } else { var plus = 0; } var app='&lt;img id="' + next + '" src="' + imgs[next].src + '"&gt;'; $('.container').width('2800px').append(app); $('.container').animate({marginLeft: (diff + plus) + "px"}, 300, function() { $('.container img:first-of-type').remove(); $('.container').width('2100px').css("margin-left", (galsize() + plus) + "px"); }); }); // end right click </code></pre> <p>This works just fine, not a problem..... I also have an interval set up to run this automatically every 5 seconds to form a slideshow...</p> <pre><code>var slideShow = setInterval(function() { $('#slideRight').trigger("click"); }, 5000); </code></pre> <p>This also works perfectly, not a problem.... However my problem is this.... I have thumbnails, when you click on a thumbnail, it should run this code until the current picture is the same as the thumbnail.... here is the code....</p> <pre><code>$('img.thumbnail').click(function() { clearInterval(slideShow); var src = $(this).attr("src"); while ($('.container img:eq(1)').attr('src') != src) { $('#slideRight').trigger("click"); } }); </code></pre> <p>When I click on the thumbnail nothing happens... I've used alert statements to try and debug, what ends up happening is this.... </p> <p>The while loop executes, however nothing happens the first time. The slide is not advanced at all. Starting with the second execution, the is('::animated') is triggered EVERY TIME and the remainder of the slideRight event is not executed...</p> <p>So my first problem, can anyone shed some light on why it doesn't run the first time?</p> <p>And my second question, is there any way to wait until the animation is complete before continuing with the loop?</p> <p>Any help would be appreciated. Thank you!</p>