Get elements just 1 level below the current element by javascript

后端 未结 8 2004
自闭症患者
自闭症患者 2021-02-05 20:30

I need to access the DOM tree and get the elements just 1 level below the current element.

Read the following code:

8条回答
  •  盖世英雄少女心
    2021-02-05 21:05

    Universal selectors can do the trick:

    var subNodes = document.querySelectorAll("#node > *");
    

    Query parts:

    #node is unique container selector

    > next slector should be applied only on childs

    * universal selector that match every tag but not text

    Can I use universal selector

提交回复
热议问题