简体   繁体   English

在Jquery中选择nth-child和nth-last-child之间的所有元素

[英]Selecting all the elements between nth-child and nth-last-child in Jquery

I know in CSS if I wanted to select certain elements between lets say the 5th child and last I would put .class-name:nth-child(5) ~ nth-last-child. 我知道在CSS中是否要在第5个孩子和最后一个孩子之间选择某些元素,我会输入.class-name:nth-​​child(5)〜nth-last-child。

So how would I go about doing this in Jquery? 那么我将如何在Jquery中做到这一点?

Not sure I understand exactly what you mean by "between lets say the 5th child and last", but let's say you mean from the 5th element up to, but not including, the last one. 不确定我确切地理解您的意思是“在第5个孩子和最后一个孩子之间说”,但可以说您的意思是从第5个元素到最后(但不包括)最后一个。 You can do pretty flexible filtering like this using $().slice() : 您可以使用$().slice()这样灵活地进行过滤:

$('.class-name').slice(4, -1);

If I understand you, I would try something like this: 如果我理解你,我会尝试这样的事情:

$('.class-name:nth-child(5) ~ .class-name:not(:last-child)');

You can see a demo of this here . 您可以在此处查看此演示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM