An HTMLCollection is a list of nodes, an interface representing a generic collection of elements (in document order) and offers methods and properties for traversing the list. The nodes are automatically updated when the underlying document is changed.
Questions tagged [htmlcollection]
161 questions
40
votes
7 answers
Typescript,'NodeListOf' is not an array type or a string type
Converting my JS to TS strict mode.
The following syntax looks fine to me but TS is complaining in the for loop on allSubMenus with:
[ts] Type 'NodeListOf' is not an array type or a string type.
What am I missing?
function…

Sam
- 1,557
- 3
- 26
- 51
25
votes
4 answers
Are HTMLCollection and NodeList iterables?
In ES6, an iterable is an object that allows for... of, and has a Symbol.iterator key.
Arrays are iterables, as are Sets and Maps. The question is: are HTMLCollection and NodeList iterables? Are they supposed to be?
MDN documentation seems to…

light
- 4,157
- 3
- 25
- 38
21
votes
1 answer
console.log of element.children shows 0 length but has three entries when expanded later
In my JavaScript, I have two elements.
I have logged the two elements and it shows the following:
Element 1:
Element 2:
The problem is:
When I console.log the children of each element (element.children) it obviously returns a list of…

David Callanan
- 5,601
- 7
- 63
- 105
20
votes
3 answers
how to iterate on HTMLCollection?
I have some elements in my HTML with class node-item, I access them in my component using:
let nodeItems = document.getElementsByClassName('node-item');
and when I log nodeItems it gives me a HTMLCollection[] with length 4.
I tried many ways but…

Fateme Fazli
- 11,582
- 2
- 31
- 48
14
votes
3 answers
Strange behavior when iterating over HTMLCollection from getElementsByClassName
I wrote a function to change the class of elements to change their properties. For some reason, only some of the elements have changed. It took me a few hours to find a solution, but it seems odd to me. Perhaps you can explain this to me.
This isn’t…

MeNa
- 1,467
- 9
- 23
12
votes
1 answer
What is the difference between a HTMLCollection and a NodeList in DOM?
I tried my Google-fu but I can't seem to find any good answer to that question. Please help.
EDIT:
Ok so I found this blog post. So they come from different DOM levels, but besides that it doesn't say much...

c00kiemonster
- 22,241
- 34
- 95
- 133
11
votes
3 answers
Can't access the value of HTMLCollection
test.html
Untitled Document