For loop for HTMLCollection elements

前端 未结 12 1240
挽巷
挽巷 2020-11-22 04:20

I\'m trying to set get id of all elements in an HTMLCollectionOf. I wrote the following code:

var list = document.getElementsByClassName(\"event         


        
12条回答
  •  滥情空心
    2020-11-22 04:32

    Alternative to Array.from is to use Array.prototype.forEach.call

    forEach: Array.prototype.forEach.call(htmlCollection, i => { console.log(i) });

    map: Array.prototype.map.call(htmlCollection, i => { console.log(i) });

    ect...

提交回复
热议问题