JavaScript innerText property

The JavaScript innerText property is used to generate the dynamic text on the HTML document and is used to get the text content of the specified node, and all its descendants. The dynamic text can be a validation message, password strength, etc.

Syntax 1: To get the text content of a node

node.innerText

Syntax 2: To set the text content of a node

node.innerText = text

Example:

<!DOCTYPE html>
<html>
<body>
<button onclick="textreturn()" id="Button">CLICK ME</button>
<p id="DOM"></p>
<script>
function textreturn() {
var x = document.getElementById("Button").innerText;
document.getElementById("DOM").innerHTML = "The text of button is: " + x;
}
</script>
</body>
</html>