ZVON > References > DOM1 Reference

childNodes (attribute)

Owning interface and usage:  
Node.childNodes

Member of these other interfaces :  
Attr, CDATASection, CharacterData, Comment, Document, DocumentFragment, DocumentType, Element, Entity, EntityReference, Notation, ProcessingInstruction, Text

Readonly:   yes

Type:   NodeList

Description:  
A NodeList that contains all children of this node. If there are no children, this is a NodeList containing no nodes.

Note:  
The content of the returned NodeList is "live" in the sense that, for instance, changes to the children of the node object that it was created from are immediately reflected in the nodes returned by the NodeList accessors; it is not a static snapshot of the content of the node. This is true for every NodeList, including the ones returned by the getElementsByTagName() method.


Example:
Text in the first DIV.
Some text in the second DIV.
Some text and element in the third DIV.
We can try another elements. It will be much more interesting.
Text in the last DIV.
Source:
       <div id="doc">
         <div>
           Text in the first DIV.
         </div>
         <div id="DDD" class="secondClass">
           Some text in the second DIV.
         </div>
         <div class="thirdClass">
           Some text and <span id="SSS">element</span> in the third DIV.
         </div>
         <div class="fourthClass">
           We can try <i>another elements</i>.
           It will be much more <b>interesting</b>.
         </div>
         <div>
           Text in the last DIV.
         </div>
       </div>
     
JavaScript:
  var main = document.getElementById('doc');
  var output1 = main.childNodes.length;
  var output2 = main.childNodes[0].nodeType;
Output:
desired your browser
white-spaces

preserved

by default
output1: 11
output2: 3
white-spaces

not-preserved

by default
output1: 5
output2: 1