Easy Tutorial
❮ Dom Met Document Getelementsbytagname Dom Prop Document Inputencoding ❯

XML DOM childNodes Property



Definition and Usage

The childNodes property returns a node list of child nodes for the specified node.

Syntax


Tips and Notes

Tip: Use the length property of the node list to count the number of nodes in a node list. Once you know the length of the node list, you can easily loop through it and extract the values you need!


Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc and displays the child nodes of the XML document:

Example

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.childNodes;
for (i=0;i<x.length;i++)
{
  document.write("Node name: " + x[i].nodeName + "<br>");
  document.write(" (node type: " + x[i].nodeType + ") ");
}

Output IE:

Output Mozilla (Firefox):


Try It Demos

Display all child nodes of all elements in the XML document


❮ Dom Met Document Getelementsbytagname Dom Prop Document Inputencoding ❯