Tag: css selectors

jquery当前可见的第n个孩子

我可以像这样设计每个第4个“项目”div jQuery(“.item:nth-child(4n)”).addClass(“fourth-item”); 并且工作正常,但后来我隐藏了一些项目,显示了其他一些项目,并希望重新做这个样式,但只有每个第四项可见的样式。 所以我有一个function,将删除这个样式并重新应用它,但我需要在重新应用样式时指定它只是每隔4个可见项目,而不是每第4个项目。 我知道“:visible”选择器但是没有看到用正确的nth-child选择器链接它,任何想法? 我尝试过这样的各种事情但无济于事…… jQuery(“.item”).removeClass(“fourth-item”); jQuery(“.item:visible:nth-child(4n)”).addClass(“fourth-item”);

:jQuery / Sizzle中的nth-of-type()?

令我感到惊讶的是, Sizzle (jQuery使用的选择器引擎)带有内置的:nth-child()选择器,但缺少:nth-of-type()选择器。 为了说明:nth-child()和:nth-of-type()之间的区别并说明问题,请考虑以下HTML文档 : :nth-of-type() in Sizzle/jQuery? body p:nth-of-type(2n) { background: red; } The following CSS is applied to this document: body p:nth-of-type(2n) { background: red; } This is paragraph #1. This is paragraph #2. (Should be matched.) This is paragraph #3. This is paragraph #4. (Should be matched.) This is not a paragraph, […]