Finding child element of parent pure javascript

后端 未结 4 1128
逝去的感伤
逝去的感伤 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:17

    If you already have var parent = document.querySelector('.parent'); you can do this to scope the search to parent's children:

    parent.querySelector('.child')
    

提交回复
热议问题