var myInterval; var myFunc = function() { var cur = $('ul li.current'); if(cur.index() == $('ul li').length - 1) { cur.removeClass('current'); $('ul li:first').addClass('current'); } else { cur.removeClass('current').next().addClass('current'); } }; //Start Interval myInterval = setInterval(myFunc, 1000);