Javascript Reference - HTML DOM childNodes Property








The childNodes property returns a collection of a node's child nodes, as a NodeList.

Browser Support

childNodes Yes Yes Yes Yes Yes

Syntax

element.childNodes

Return Value

A NodeList object, representing a collection of nodes.

Example

The following code shows how to get a collection of the body element's child nodes.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction()<!--   w w  w  .  jav a2 s. co m-->
{
    var txt="";
    var c=document.body.childNodes;
    for (i=0; i<c.length; i++){
      txt=txt + c[i].nodeName + "<br>";
    };
    console.log(txt);
}
</script>
</body>
</html>

The code above is rendered as follows: