Get elements just 1 level below the current element by javascript

后端 未结 8 2014
自闭症患者
自闭症患者 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:22

    In my opinion the easiest way to do this is to add a class name to the first level child nodes:

    and then to use the method getElementsByClassName, so in this case:

    document.getElementById('node').getElementsByClassName('level_1');
    

提交回复
热议问题