Home › Forums › JavaScript › Loop/count to provide visual clues › Re: Loop/count to provide visual clues
I got this working with the following code:
$(‘.item-list ul li’).each(function(i) {
$(‘.visual-cue p’).append("<span></span>");
});
$(‘.visual-cue p span:first’).addClass(‘active’);
$(‘#carousel-next’).click(function () {
$(‘.visual-cue p span.active’).removeClass(‘active’).next().addClass(‘active’);
});
$(‘#carousel-prev’).click(function () {
$(‘.visual-cue p span.active’).removeClass(‘active’).prev().addClass(‘active’);
});
I have one small issue though. The carousel I am using continuously loops through the results. The above code does not. I am looking for a way to take the above code and have it work the same as the carousel (if on the last item and the user clicks the next button, this would jump to the first item in the list – and if on the first item and the user clicks the previous button, this would jump to the last item in the list).
Any ideas?
Thanks