For loop for HTMLCollection elements

前端 未结 12 1098
挽巷
挽巷 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:44

    I had a problem using forEach in IE 11 and also Firefox 49

    I have found a workaround like this

    Array.prototype.slice.call(document.getElementsByClassName("events")).forEach(function (key) {
            console.log(key.id);
        }
    

提交回复
热议问题