This page is Almost Ready

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

childNodes

Summary

Gets a collection of direct Node descendants of the Node, including Element, Text and any other type of nodes.

Property of dom/Nodedom/Node

Syntax

Note: This property is read-only.

var result = element.childNodes;

Return Value

Returns an object of type

A live collection of the direct Node descendants of the Node.

Examples

This example shows how to assign to a variable the childNodes collection of the body object.

<script>
var aNodeList = oBody.childNodes;
</script>
<body id="oBody">
<span id="oSpan">A Span</span>
</body>

This example shows how to assign to a variable the childNodes collection of a node created with the createElement method.

var oParentNode = document.createElement("DIV");
var oNode = document.createElement("B");
document.body.insertBefore(oParentNode);
oParentNode.insertBefore(oNode);
var aNodeList = oParentNode.childNodes;

Notes

The childNodes collection can contain Element and Text nodes. If you check the childNodes collection of an element created through standard HTML, you encounter Text nodes in unexpected places—in place of line breaks, for example. Alternately, if you create an element using the Document Object Model (DOM), no unintended Text nodes are created.

Attributions