I am trying to carry a class between li\'s with combine each() and eq() methods when buttons clicked. I am using same code with previo
If for some reason you need the index, you could always do:
$('.prev').on('click', function() {
var i = $(".active").index();
i--;
$(".active").removeClass('active');
$('li').eq(i).addClass('active');
});
$('.next').on('click', function() {
var i = $(".active").index();
i = i >= $('li').length-1 ? 0 : i+1;
$(".active").removeClass('active');
$('li').eq(i).addClass('active');
});
FIDDLE
If not :
$('.prev, .next').on('click', function() {
if ($(".active")[$(this).attr('class')]().index()!=-1)
$(".active").removeClass('active')[$(this).attr('class')]().addClass('active');
});
FIDDLE