DOM Node.textContent Property
The textContent property gets or sets the text inside a node and its descendants. Setting it is the safe way to insert text, because HTML in it isn't parsed.
Description
The textContent property returns the text content of a node and all its descendants, joined together, including text inside <script> and hidden elements. Setting it removes all children and inserts a single text node.
Because the value is treated as plain text, setting textContent is the safe way to show user-supplied text: any HTML in it appears literally instead of being run. It's also faster than innerHTML and innerText, since it doesn't involve parsing or layout.
For the document itself, textContent is null; use document.documentElement.textContent instead. Reading it from a large element returns all its text in one string, including white space from the HTML source, so trim() the result when comparing it.
Syntax
node.textContent
node.textContent = textValue
A string containing the text of the node and all its descendants. Setting it replaces all children with a single text node.
Example
Browser Support
The following information will show you the current browser support for the Node.textContent property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





