Javascript get all direct children

后端 未结 1 944
感情败类
感情败类 2021-01-17 15:31

I need to get all the direct children of an element. As it is here:

相关标签:
1条回答
  • 2021-01-17 16:00

    One option is to use the direct child combinator, >, and the universal selector, *, in order to select direct children elements of any type:

    document.querySelectorAll('.element > *');
    

    Alternatively, there is also a .children property that will return all the direct children elements:

    document.querySelector('.element').children;
    
    0 讨论(0)
提交回复
热议问题