跳过JQuery中的前N个元素

我想知道,我怎样才能跳过JQuery中的前N个元素。 像这样的东西:

1
2
3
4
...
$('#test > div').skip(2)

应该回来

 
3
4
...

我知道我可以使用:not(:first-child):not(:first-child + div)...选择器N次,但是有更好的方法吗?

jQuery有一个gt选择器 。 (比…更棒)。

 $('#test > div:gt(1)') 

或者您可以使用切片function

 $('#test > div').slice(2) 

使用.slice()函数,它根据索引为您提供元素子集。

 $('#test > div').slice( 2 ) 

参考: http //api.jquery.com/slice/

我想你正在寻找:gt选择器: http : //api.jquery.com/gt-selector/注意你从0开始计数。

尝试:

 $('#test > div:gt(1)') 

跳过第一个 – 例如:

$(“#spaccordion li:gt(0)”)。addClass(“collapsed”);

除第一个项目外,所有

  • 项目都将具有“折叠”类