innerText in javascript

innerText in javascript

In javascript we can add or retrieve string contents which are visible in a web page, using innerText property.

Syntax
element.innerText

Example 1 - set text content

Try Yourself

Example 2 - get text content

Try Yourself

Difference between innerHTML and innerText

InnerText is used when there is a need to add or retrieve plain text content, even if it is an HTML content it is render as plain text.

Unlike innerText, innerHTML is used to encode or decode the HTML content.

Example

Try Yourself