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() {/*w w w . j a v a 2 s. com*/ 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>