【问题标题】:How to use method position() after method children()如何在方法 children() 之后使用方法 position()
【发布时间】:2015-07-16 11:43:47
【问题描述】:

我需要通过position()方法获取元素A的位置属性,但我只知道A"a" 标记的子代。 所以我使用$("a").children().position()。但是失败了,因为 children() 方法返回的是一个 jQuery 对象。我这样做$("a"),children()[0].position()(我知道 A"a"tag 的第一个孩子)。但例外是这样的

未捕获的 TypeError: $(...).children(...)[0].position 不是函数

请帮忙,谢谢

【问题讨论】:

    标签: jquery position children


    【解决方案1】:

    $("a").children() 匹配所有a 标签的所有子标签。

    $("a").children()[0] 获取第一个匹配项,作为 DOM 元素。相反,使用 .first() 返回另一个 jquery 对象。

    $("a").children().first().position()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      相关资源
      最近更新 更多