JavaScript · DOM and events

textContent

Reads or writes text safely. The browser escapes it, so it cannot inject markup.

Syntax
el.textContent = "…"

Example

Try it

Notes

Prefer textContent over innerHTML for any value that came from a user.

More in this group

addEventListener append classList closest createElement dataset element.style Event delegation

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course