Easy Tutorial
❮ Dom Obj Colgroup Prop Datetime Local Name ❯

HTML DOM textContent Property

Element Object

Example

Get the text content of the first button element:

Output result:


Definition and Usage

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

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

Tip: Sometimes the textContent property can be replaced by the nodeValue property, but remember that this property can also return the text of all child nodes.

Example

Get the text content of all lists:


Browser Support

All major browsers support the textContent property.

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


Syntax

Set node text content:

Return node text content:

Technical Details

Return Value: String, representing the text node and all child nodes
DOM Version Core Level 3 Node Object
--- ---

Element Object

❮ Dom Obj Colgroup Prop Datetime Local Name ❯