For loop for HTMLCollection elements

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

    if you use oldder varsions of ES, (ES5 for example), you can use as any:

    for (let element of elementsToIterate as any) {
          console.log(element);
    }
    
    

提交回复
热议问题