For loop for HTMLCollection elements

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

    You want to change it to

    var list= document.getElementsByClassName("events");
    console.log(list[0].id); //first console output
    for (key in list){
        console.log(list[key].id); //second console output
    }
    

提交回复
热议问题