javascript - jQuery 选择器获取未知深度下的(第 n 个)元素?

标签 javascript jquery html dom jquery-selectors

选择特定的<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/

相关文章:

javascript - 循环总是返回数组的最后一个值

jQuery 圆形 slider

javascript - 为什么我不能在 onClick html 事件上传递 angularJS 参数?

javascript - 如何使我的 div 居中并使它们与媒体查询堆叠

javascript - iOS UIAutomation 找不到搜索栏

javascript - Redux 中间件在 next() 之前改变状态

javascript - 在 "tap, click"事件触发两次。如何避免呢?

c# - 设置 RadioButtonList 的选定值无法按预期工作

带有 HTML 前端的 Python

php - 集成 PayPal 快速结帐的更简单方法?