如何给计数器的相应元素下课

How to give classes to the corresonding element of the counter?

本文关键字:元素 计数器      更新时间:2023-09-26

如果我想将类添加到计数器的相应元素中,我将如何操作?

我确实有类似的东西

var li_counter = 0;
   $("#trigger_heritage").click(function () {
        if(heritage_position>=heritage_versatz*13){
            li_counter++;
            $(".heritage_nav" li[li_counter]).addClass("activeheritage");
        }
        else{ // Something else
        }
    });

我想将一个类应用于heritage_nav块的 li 元素有相应的对立。如果用户点击了 5 次,则heritage_nav的第 5 个子元素将获得类。

谢谢!

var li_counter = 0;
   $("#trigger_heritage").click(function () {
        if(heritage_position>=heritage_versatz*13){
            li_counter++;
         $(".heritage_nav li:eq("+li_counter+")").addClass("activeheritage");
        }
        else{ // Something else
        }
    });

也许这会对你有所帮助,

var li_counter = 0;
$("#trigger_heritage").click(function () {
    if(heritage_position>=heritage_versatz*13){
        li_counter++;
        $(".heritage_nav").find("li:nth-child(" + li_counter + ")").addClass("activeheritage");
        //if you want to add class to this div
        $(".heritage_nav").addClass("your-class");
    }
    else{ // Something else
    }
});