HTML DOM innerText Property

The innerText property is used to write th dynamic text on the html elements. It basically sets or returns the text content of the specified node, and all its descendants. Also note that at here the text data will not be interpreted as html text but a normal text. The syntax of innerText is as follows :

To get the innerText property of a node :
 node.innerText
To set the innerText property of a node :
 node.innerText = content
where the content specifies the HTML content of an element.

Example :
<html>
<head>
  <script>
    function printFunc() {
      var text = document.getElementById('box').value;
      document.getElementById('demo').innerText = "Hello " + text;
    }
  </script>    
</head>
<body>
  <p>Enter your Name :</p>
  <input type="text" id="box"/>
  <input type="button" onclick="printFunc()" value="Click Here"/>
  <p id="demo"></p>
</body>
</html>
Output :


Enter your Name :



The above code will set the paragraph text using innerText property by get the value of input box.


Next Topic :