Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM textContent Property

HTML DOM textContent Property

Element Object Reference Element object

Example

Get the text content of the first button element:

document.getElementsByTagName("BUTTON")[0].textContent;

Output result:

Try it

Try it »


Definition and Usage

The textContent property sets or returns the text content of the specified node.

If you set the textContent property, any child nodes are removed and replaced with a text node containing the specified string.

Tip: In some cases the textContent property can be replaced by the nodeValue property, but keep in mind that this property can also return the text of all child nodes.

Example

Get the text content of all lists:

document.getElementById("myList).textContent;

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the textContent property

Note: Internet Explorer 8 and earlier versions of IE do not support this property.


Syntax

Set the node text content:

node

.textContent=

text

Return the node text content:

node

.textContent

Technical Details

Return Value: A string representing the text node and all nodes
DOM version Core Level 3 Node Object

Element Object Reference Element object