textContent

The DOM property that reads or replaces all the text inside a node, treating anything you assign as plain text rather than markup.

Choosing innerHTML instead for untrusted text opens the page to cross-site scripting.

In more detail

Because textContent never parses HTML, assigning user data to it cannot inject scripts, unlike innerHTML. Use it whenever you only need to display text.

Related terms

Taught in

References