HTML DOM nodeValue Property

The nodeValue property sets or returns the node value of the specified node. The syntax of nodeValue property is as follows :
  node.nodeValue
Also note that if the node is an element node, then the nodeValue property will return null because text inside elements are considered to be text nodes. So in order to get the nodeValue from HTML elements we have to use childNodes property. The childNodes property returns a collection of a node's child nodes, as a NodeList object. And by the below code we can get the nodeValue of an HTML element :
  node.childNodes[0].nodeValue;
Example :
<html>
<body>
  <p id="demo" class="paragraph" style="color: blue;">Hello world</p>
  <button onclick="myfunc()">Click Here</button>
  <p id="echo1"></p>
  <p id="echo2"></p>
  <script>
    function myfunc() {
      var val1 = document.getElementById("demo").childNodes[0].nodeValue;
      document.getElementById("echo1").innerText = "Paragraph value : " + val1;
      var val2 = document.getElementsByTagName("button")[0].childNodes[0].nodeValue;
      document.getElementById("echo2").innerText = "Button value : " + val2;
    }
  </script>
</body>
</html>
Output :

Hello world



Similarly theres other node properties like node.nodeName, node.nodeType, node.nodeValue etc.


Next Topic :