JavaScripture
Contribute via GitHub Feedback

JavaScript Text : CharacterData

Text is a Node that represents the text content of the document. The text content of elements like Spans is stored in Text nodes.

Constructors

new Text([data = '' : String]) : Text

Creates a new Text with the specified data. Can also be created with document.createTextNode().

Example:

Run

Results:

 

Instance Properties

wholeText : String  

Returns a string containing the data of this and data of all adjacent Text siblings of this. Only the data of Texts is joined, wholeText does not walk into other adjacent Node types to pull out the text.

Example:

Run

Results:

 

Instance Methods

splitText(offset : Number) : Text

Splits this into 2 Text nodes at the specified offset into data. The first portion of data stays in this and the remainder is placed in a new Text that is returned by the call to splitText(). The remainder Text is inserted after this in this.parentNode.

Example:

Run

Results: