Finding child element of parent pure javascript

后端 未结 4 1127
逝去的感伤
逝去的感伤 2020-12-02 06:48

What would the most efficient method be to find a child element of (with class or ID) of a particular parent element using pure javascript only. No jQuery or other framework

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 07:02

    Just adding another idea you could use a child selector to get immediate children

    document.querySelectorAll(".parent > .child1");
    

    should return all the immediate children with class .child1

提交回复
热议问题