简体   繁体   English

获取当前节点的所有子节点

[英]Get all children of the current node

<div class='1'>
  <div class='2'>
    <div class='3'>
    </div>
  </div>
</div>

query('.1').children() // returns [<div class='2'></div>]

Is is possible to access 3rd level children by using query().children() instead of using something like query('.1 .2 .3')? 是否可以通过使用query()。children()而不是使用诸如query('.1 .2 .3')?类的方法来访问3级子级query('.1 .2 .3')?

Basically, I would like to access all children of the current element without hard-coding its Id, eg query('#foo .3') 基本上,我想访问当前元素的所有子元素而无需对其ID进行硬编码,例如query('#foo .3')

You could use: 您可以使用:

  • element.querySelectorAll('div') to get all <div> children of element element.querySelectorAll('div')获取element所有<div>element
  • element.querySelectorAll('[class]') to get all children of element that does have a class attribute element.querySelectorAll('[class]')获取具有class属性的element所有子element
  • document.querySelectorAll('div[class]') for the whole html document document.querySelectorAll('div[class]')用于整个html文档

You can use any CSS selector as a parameter for querySelectorAll() . 您可以使用任何CSS选择器作为querySelectorAll()的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM