Home >>Javascript Tutorial >Javascript innerText

Javascript innerText

InnerText in JavaScript

The innerText property in JavaScript is used to write the dynamic text on the HTML document. In this property the text will be not interpreted as html text instead they will be interpreted as normal text.

InnerText Property in JavaScript is mostly used in the web pages in order to generate the dynamic content like writing the validation message, password strength and many more.

Here is an example of the innerText in JavaScript to understand it from a simple point of view:

In the following example, the password strength will be determined:

function validate() {  
var msg;  

<form name="myForm">  
<input type="password" value="" name="userPass" onkeyup="validate()">  
Strength:<span id="mylocation">no input</span>  
Output :
Strength:no input

Click the button to get the inner text of the button element.

<button onclick="myFunction()" id="myBtn">Click me</button>
<p id="msg"></p>
function myFunction() {
  var x = document.getElementById("myBtn").innerText;
  document.getElementById("msg").innerHTML = x;  
Output :


No Sidebar ads