Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

childNodes property

Retrieves a collection of HTML Elements and TextNode objects that are direct descendants of the specified object.

Syntax

JavaScript

p = object.childNodes

 

Property values

Type: Object

Array containing the children of a specified object.

Standards information

There are no standards that apply here.

Remarks

The childNodes collection can contain HTML Element and TextNode objects.

If you check the childNodes collection of an element created through standard HTML, you encounter TextNode objects in unexpected places—in place of line breaks, for example. Alternately, if you create an element using the Document Object Model (DOM), Windows Internet Explorerdoesn't create extraneous TextNode objects.

In Microsoft Internet Explorer 6, This collection now applies to the attribute object.

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</spn>
</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("strong");

document.body.insertBefore(oParentNode);
oParentNode.insertBefore(oNode);

var aNodeList = oParentNode.childNodes;

See also

About the W3C Document Object Model

 

 

Show:
© 2017 Microsoft