I am new to typescript and I'm trying to iterate over a HTMLCollection got by document.getElementsByClassName()
. My code is:
let tag_list = document.getElementsByClassName("...") as HTMLCollectionOf<HTMLLinkElement>;
for (const tag of tag_list) {
//do sth with tag.href
}
But it turns out that "TS2495: Type 'HTMLCollectionOf' is not an array type or a string type." So what is the best way I can do to prevent this error?