JQuery每6个LI添加一个类

时间:2012-05-15 13:50:38

标签: jquery

我似乎遇到了这个jquery代码的问题。

我想在第1个课程中添加一个课程,然后每6个

  • 添加一个课程...我正在获得第1个和第6个但是在第3个圆周上它正在进行第11个而不是12。

    Here is the code:Query:
    
    $('ul li:nth-child(5n+1)').addClass("red").text("Here");
    
    Here is the css:
    
    li { background-color:blue; }
    .red{ background-color: red; }
    
  • 1 个答案:

    答案 0 :(得分:7)

    这应该适合你:

    $('ul li:first, ul li:nth-child(6n)').addClass("red").text("Here");