Sounds like you're overthinking it. You've observed the difference between childNodes
and children
, which is that childNodes
contains all nodes, including text nodes consisting entirely of whitespace, while children
is a collection of just the child nodes that are elements. That's really all there is to it.
There is nothing unpredictable about either collection, although there are a couple of issues to be aware of:
childNodes
while other browsers dochildren
while other browsers only have elementschildren
, firstElementChild
and friends are just conveniences, presenting a filtered view of the DOM restricted to just elements.