【发布时间】:2021-08-03 23:00:16
【问题描述】:
我想获取与 class="foo" 匹配的节点的后代。
问题是:我不知道这个后代会有多深。
我知道我可以使用 >
或者如果我知道它有多深,我可以使用多个 > > > >
我可以只使用 class="foo" 但我会得到与 class="foo" 匹配的目标的后代。
是 div.class="foo":first-child 解决方案吗?
div id="im_here"
div id="child"
......
div class="foo" <= I want this
......
div class="foo" <= not that
......
div class="foo" <= not that
......
【问题讨论】:
-
我认为单靠 CSS 不会做到这一点。你可能需要 JavaScript
-
在jquery中你可以使用
$(".foo:first")