var currentItem = -1; var direction = 1; $(document).ready(function(){ switchItem(); setInterval(switchItem, 5000); }); function switchItem(){ currentItem = (currentItem+1) % ($(".parent .child").size()); // hide the visible one. $(".parent .child:visible").fadeOut(500, function() { //now that the hide is done, show the current one. $(".parent .child").eq(currentItem).fadeIn(500); }); }