children only contains
element nodes.
childNodes contains all
node types including:
text nodes,
whitespace,
comments,
and elements.
This difference becomes important
when reusing or enhancing existing
DOM structures.
children and
childNodes
during callback mutations.
childNodes
instead of only elements.
tree
.setChildren(
({ children }) => [
...children
]
);
// text nodes disappear
tree
.setChildren(
({ childNodes }) => [
...childNodes
]
);
// all nodes preserved
children
excludes text nodes
childNodes
preserves exact DOM structure