XML DOM - Text object

The Text object represents the text content of an element or attribute.

Text object description

Text nodes represent a series of plain text in an HTML or XML document. Since plain text appears in the elements and attributes of HTML and XML, Text nodes are usually found as child nodes of Element nodes and Attr nodes.

Text nodes inherit CharacterData interfaceThe text content of a Text node can be accessed through the data attribute inherited from CharacterData or the nodevalue attribute inherited from the Node interface.

Methods or the splitText() method defined by the Text interface itself, inherited from CharacterData, can be used to manipulate Text nodes. A new Text node can be created using document.createTextNode().

Text nodes have no child nodes.

For methods on removing empty Text nodes from the document subtree and merging adjacent Text nodes, please refer to "Node.normalize()Reference page.

Text object properties

Attribute Description IE F O W3C
data Set or return the text of the element or attribute 6 1 9 Yes
isElementContentWhitespace Determine whether the text node contains whitespace content. No No No Yes
length Return the text length of the element or attribute 6 1 9 Yes
wholeText Return all text of adjacent text nodes to this node in the order of the document No No No Yes

Text object methods

Method Description IE F O W3C
appendData() Append data to the node 6 1 9 Yes
deleteData() Delete data from the node 6 1 9 Yes
insertData() Insert data into the node 6 1 9 Yes
replaceData() Replace the data in the node 6 1 9 Yes
replaceWholeText() Use the specified text to replace this node and all adjacent text nodes No No No Yes
splitText() Split a Text node into two. 6 1 9 Yes
substringData() Extract data from the node 6 1 9 Yes

Related pages

XML DOM Reference Manual:CharacterData object