Home » innerText Vs. innerHTML

innerText Vs. innerHTML

by Online Tutorials Library

innerText Vs. innerHTML

innerText and innerHTML are the properties of JavaScript.

innerText

innerText is used to print the plain text information between tags and requires some layout system information. It also ignores the space.

Syntax:

Code:

innerHTML

innerHTML is used to print content between labels, including text information. Cross site security attaks are the main disadvantage of innerHTML.

Syntax:

Code:

Differene between innerText and innerHTML

The below table shows the differene between innerText and innerHTML –

innerText innerHTML
Retrieves and sets the content in plain text. Retrieves and sets the content in HTML format.
We can not insert the HTML tags. We can insert the HTML tags.
It ignores the spaces. It considers the spaces.
It returns text without an inner element tag. It returns a tag with an inner element tag.

Next TopicDifference between

You may also like