X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

XML DOM childNodes Property


Node Object Reference Node Object

Definition and Usage

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

Tip: You can use the length property to determine the number of child nodes, then you can loop through all child nodes and extract the info you want.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The childNodes property is supported in all major browsers.


Syntax

nodeObject.childNodes

Technical Details

Return Value: A NodeList object representing a collection of nodes
DOM Version Core Level 1


Example

The following code fragment loads "books.xml" into xmlDoc using loadXMLDoc() 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("Nodename: " + x[i].nodeName);
  document.write(" (nodetype: " + x[i].nodeType + ")<br>");
  }

Output IE:

Nodename: xml (nodetype: 7)
Nodename: #comment (nodetype: 8)
Nodename: bookstore (nodetype: 1)

Output Firefox, Opera, Chrome, and Safari :

Nodename: #comment (nodetype: 8)
Nodename: bookstore (nodetype: 1)

Try it yourself »

Try-It-Yourself Demos

Display all child nodes of all the elements in the XML document


Node Object Reference Node Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook