JS: iterating over result of getElementsByClassName using Array.forEach

前端 未结 11 1917
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 06:42

I want to iterate over some DOM elements, I\'m doing this:

document.getElementsByClassName( \"myclass\" ).forEach( function(element, index, array) {
  //do s         


        
11条回答
  •  盖世英雄少女心
    2020-11-22 07:16

    Is the result of getElementsByClassName an Array?

    No

    If not, what is it?

    As with all DOM methods that return multiple elements, it is a NodeList, see https://developer.mozilla.org/en/DOM/document.getElementsByClassName

提交回复
热议问题