Get first child node of specific type - JavaScript

后端 未结 4 1868
刺人心
刺人心 2021-02-04 23:19

Is it possible to get a child dom element, which will be the first child of a specific type.

For example in both of these examples I want to get the img ele

4条回答
  •  执念已碎
    2021-02-04 23:41

    You can also use querySelector:

    var firstImg = document.querySelector("#mylink > img:first-of-type");
    

提交回复
热议问题