childNodes returns child nodes (element nodes, text nodes, and comment nodes).
children returns child elements (not text and comment nodes)
I understand that both properties output DOM Element nodes === HTML source elements.
But what are the former’s “text nodes” exactly?
Are they textContnet or innerHTML or both?
Also, what are the former’s “comment nodes” here?
I never heard the term comment nodes. Are they simply Markup Comments such as HTML comments (<!-- -->) or something else?
<div>
Hello
<strong>world</strong>
<!-- and everyone on it! -->
<div>
Here the div contains three nodes:
a text node “hello”
a strong element, that itself contains a text node “world”
a comment node “and everyone on it!”
All of these are nodes, but only strong is an element.
As for your question, the DOM is not a node, it the entire model that contains nodes. HTML is a node, but only because it is an element. It’s not a special kind of node. Lastly, attributes are not nodes, they are attributes of a node.
Node is the base (abstract) class for all things that implement its methods and properties. This does include the vast majority of things in a webpage; they extend Node into their own interface abstraction classes, like Document, Element, Attr, and all the flavors of CDATA floating around.
Not entirely. In my example above the textContent of the div is “Hello world”, but there is no node that only has that content. There is one with “Hello” and one with “world”.
Remember that DOM stands for Document Object Model. A node then is a base class in that object model that contains properties common which all the other objects then extend. Perhaps if you skim through that actual DOM specification, it’ll make things clearer.
Alternatively, remember the DOM is structured in a tree format. A node then represents any potential branching point on that tree.
textContent is not a single thing like a node. It’s a property that when accessed runs through a particular algorithm to determine what the textual content of a node is. It’s like a function essentially, but disguised as a property.