The childNodes
property returns a collection of
a node's child nodes, as a NodeList.
childNodes |
Yes | Yes | Yes | Yes | Yes |
element.childNodes
A NodeList object, representing a collection of nodes.
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: