Javascript - innerText property

  • javascript innerText
  • Example of innerText property

The innerText property serves the purpose of inserting dynamic text into an HTML document. In this case, the text will be treated as plain text rather than being parsed as HTML.

It is primarily utilized in web pages to create dynamic content, including elements like displaying validation messages, assessing password strength, and more.

Javascript innerText Example

In this instance, we will showcase the strength of a password when the key is released following a press.

Example

<script type="text/javascript" >

function validate() {

var msg;

if(document.myForm.userPass.value.length>5){

msg="good";

}

else{

msg="poor";

}

document.getElementById('mylocation').innerText=msg;

 }



</script>

<form name="myForm">

<input type="password" value="" name="userPass" onkeyup="validate()">

Strength:<span id="mylocation">no strength</span>

</form>

Output of the above example

Input Required

This code uses input(). Please provide values below: