Element NodeList Property - Return the number of child nodes of the <body> element: - Javascript DOM

Javascript examples for DOM:Element NodeList

Description

Element NodeList Property - Return the number of child nodes of the <body> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body><!-- This is a comment node! -->

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from w  w  w . ja  va  2 s .  c om*/
    var nodelist = document.body.childNodes.length;
    document.getElementById("demo").innerHTML = nodelist;
}
</script>

</body>
</html>

Related Tutorials