Like any of the 12 node types, Document, Element, and Text nodes have a childNodes member containing a NodeList, which is an arraylike object. childNodes is that it contains any child nodes, which is the direct descendants, of a parent node.
For Text nodes, childNodes will always be empty and therefore have a length of 0. And also childNodes will never contain null. The childNodes will always contain a NodeList object, even if the parent node is childless.
A document can have two children.
// [DocumentType, html]
First, a DocumentType node for
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
Second, an Element node representing our <html> element. Note that, for document, childNodes may
contain only one Element node and one DocumentType node. Note too that document has a member
named documentElement that refers to the one Element child node that it is permitted by DOM.
For web pages, documentElement will always refer to the <html> Element node.
To query an element in a NodeList, use the  operator.
Another way to query a NodeList element is with NodeList.item().
document has a few shortcut members referring to <body>, <html>, and window. Those are named body, documentElement, and defaultView, respectively.
var yogurt = "Brown Cow";
// "Brown Cow"
// "Brown Cow"
yogurt = "Stonyfield";
The HTML element has two children—the head and the body elements. You can access them using the childNodes array-like collection.
Any child has access to its parent through the parentNode property.
For the below example, get the child nodes.
<p class="opener">first paragraph</p>
<!-- and that's about it -->
Assign a reference to body to a variable
var bd = document.documentElement.childNodes;
Get children of the body element.
How come body has 9 children?
3 paragraphs plus one comment makes 4 nodes. The white space between these 4 nodes makes 3 more text nodes. This makes a total of 7 so far. The white space between body and the first p is the eighth node. The white space between the comment and the closing </body> is another text node. This makes a total of 9 child nodes.
Use hasChildNodes() to find out if a node has any children, .