Name

Text — a run of text in a document

Inherits from

Node

Synopsis

A Text node represents a run of plain text in a document and typically appear in the document tree as children of Element. The textual content of a Text node is available through the data property or through the nodeValue and textContent properties inherited from Node. You can create a new Text node with Document.createTextNode(). Text nodes never have children.

Properties

string data

The text contained by this node.

readonly unsigned long length

The length, in characters, of the text.

readonly string wholeText

The text content of this node and any adjacent text nodes before or after this one. If you’ve called the normalize() method of the parent Node, this property will be the same as data.

Methods

Unless you are writing a web-based text editor application, these methods are not commonly used.

void appendData(string text)

This method appends the specified text to the end of this Text node.

void deleteData(unsigned long offset, unsigned long count)

This method deletes characters from this Text node, starting with the character at the position offset and continuing for count characters. If offset plus count is greater than the number of characters in the Text node, all characters from offset to the end of the string are deleted.

void insertData(unsigned long offset, string text)

This method inserts the specified text into the Text node at the specified offset.

void replaceData(unsigned long offset, unsigned long count, string text

Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.