选择特定的<div>
(例如 <div>
注释为 <!-- This one!
)
请记下所有 <..>
元素在所有级别都是未知元素,但没有 <div>
的。
<div></div>
<div class="class1">
<..>
<..></..>
<div></div>
<div></div>
<div> <!-- 3rd-child div, of its parent -->
<..></..>
<..>
<div></div>
<div></div> <!-- This one! The 2nd-child div, of its parent -->
<div></div>
</..>
</div>
<div></div>
</..>
</div>
在这种情况下,我能想到的唯一逻辑是:
- 仅限元素类型
<div>
s 和nth
( sibling 中的)人数是已知的。 - 中间元素是
unknowns
。可以<p>
或<table>
或<ul>
无论如何,但不是<div>
又来了。 - 级别未知。
所以:
- 目标
<div>
递归地位于div#class1
下 - 这是
2nd <div>
里面3rd <div>
的div#class1
我怎样才能得到它?
最佳答案
对不起大家,我已经有了自己的答案:
$("div.class1 div:eq(2) div:eq(1)").html()
关于javascript - jQuery 选择器获取未知深度下的(第 n 个)元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11646256/