How to create simple next and prev trigger button for slider's pagination buttons?

前端 未结 5 1079
滥情空心
滥情空心 2020-12-11 12:39

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

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 13:20

    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"

提交回复
热议问题