如何在querySelector中组合属性和nth-of-type?

亚米尔·布加塔斯(Yamil Abugattas)

我正在尝试通过属性选择表中的一个单元格(可以使用querySelector(“ [data-name]”),但是我希望它仅返回第三列中的元素。是否可以合并一个nth-of-type(2)进行属性搜索?

我尝试使用querySelector(“ [数据名称]:nth-​​of-type(2)”],但这不起作用。

深的

对于第3列,请尝试使用nth-of-type(3)

:nth-​​of-type()是一个CSS选择器,第一个孩子的索引将是1

http://www.w3schools.com/cssref/sel_nth-of-type.asp

console.log(document.querySelector("table tr [data-name]:nth-of-type(3)"));
<table>
  <tr>
    <td data-name="1">1</td>
       <td data-name="2">2</td>
        <td data-name="3">3</td>
    <tr>
      </table>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在IE8和更低版本的浏览器中应用伪类(nth-of-type)

如何使用 css 選擇器 nth-of-type 和 nth-child 在 Python Selenium 中定位元素

如何在Kentico中删除javascript type属性

如何在类中使用Tr:nth-of-type(even)?

如何在xunit / autofixture中组合PropertyData和AutoNSubstituteData属性?

如何在Typescript中创建具有Type1的所有属性或Type2的所有属性的类型?

CSS中的nth-type和nth-child无法正常工作

访问 Func<Type> 的 Type 属性

如何在[Type:[Type]]()类型的字典中过滤值

:nth-child() 和 :nth-of-type() 不起作用

如何在 PostgreSQL 中创建 TYPE?

如何在 OroPlatform 中实现 Select Type?

如何在 Rust 中匹配 Pin<Type>?

如何在列表中为每个 `type` 属性显示一项?

如何更改Castor映射以从XML输出的元素中删除“ xmlns:xsi”和“ xsi:type”属性?

如何在硒中查找xpath或查找标签输入和type ='image'的元素

如何在GmailApp.sendmail中设置Content-type和MIME-Version标头?

Typescript Type与type没有共同的属性

如何访问模型属性以在IEnumerable Type中创建texboxfor?

摆脱xs:type属性

Serilog删除$ type属性

Typescript是对象属性的Type

type name() 和 type name = type() 有什么区别?

CSS技巧:nth-of-type()

CSS Nth of Type 未定位

type [] varName和type varName []之间的区别?

type和const type的类型特征

<type'generator'>和<type'xrange'>之间的区别

nth-of-type(1) 和 first-of-type 伪类的区别