Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Loop/count to provide visual clues Re: Loop/count to provide visual clues

#62689
Rule13
Member

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