Get the node name, node value and the node type of the <div> element's first child node:
Click the button get the node name, node type and node value of the div's first child.
<!DOCTYPE html> <html> <body> <div id="myDIV">This is a div element.</div> <br> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w w w. j ava2 s .c o m*/ var x = document.getElementById("myDIV").firstChild; var txt = ""; txt += "The node name: " + x.nodeName + "<br>"; txt += "The node value: " + x.nodeValue + "<br>"; txt += "The node type: " + x.nodeType; document.getElementById("demo").innerHTML = txt; } </script> </body> </html>