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
I'd try using something more like:
Here is working jsFiddle.
$(".next").click(function(){
if($("li.active").next().length > 0){
$("li.active").removeClass("active").next("li").addClass("active");
}
});
$(".prev").click(function(){
if($("li.active").prev().length > 0){
$("li.active").removeClass("active").prev("li").addClass("active");
}
});
using the 'next' selector: Jquery Next
I avoid math when possible. Counting is hard :-). That said I'm thinking your problem above may be with the index. Hard to say. I'd avoid using selectors like "li" when dealing with a list like this. Try putting a class on the 'ul' portion of it and addressing your li's as: ".myList li"