Represents a text node in a document.
Platform Support
Constructors
Represents a text node in a document.
|
Show Details |
5.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
Text() : Text
Represents a text node in a document.
Returns
- Visibility
- internal
|
Inherited Properties
Character data of the current node.
|
Show Details |
no |
1.0+ |
no |
7.0+ |
1.0+ |
- Remarks
- The
data property does not have a size limitation, but data is subject to the limitations of the
size of a String object. If the content data is too large, use substringData to retrieve
the character data in chunks.
- Availability
-
HTML DOM Level 2|W3C
|
Length of the content of the data property or substringData method.
|
Show Details |
no |
1.0+ |
no |
7.0+ |
1.0+ |
- Remarks
- Length of the content available from the
data property or the substringData method. If the content
of data is empty, the value of length will be zero.
- Availability
-
HTML DOM Level 2|W3C
|
Inherited Functions
Appends the specified string to the node text.
|
Show Details |
6.0+ |
1.0+ |
no |
7.0+ |
1.0+ |
Parameters
String |
arg |
String to append. |
Returns
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/data.html
- Remarks
- Appends the specified string to the end of the current character data content, which will then be available through the
data
property.
- Throws
-
- Raises a NO_MODIFICATION_ALLOWED error if the node is read-only.
- See Also
-
CharacterData.deleteData|CharacterData.insertData|CharacterData.replaceData
- Availability
-
HTML DOM Level 2|W3C
|
Deletes the indicated range of text.
|
Show Details |
6.0+ |
1.0+ |
no |
7.0+ |
1.0+ |
Parameters
Number |
offset |
Character offset inside the content from which to start deleting. |
Number |
count |
Number of characters to delete. If the range of characters is greater than the length of the content of the node, then all
characters from offset to the end of the string are deleted.
|
Returns
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/data.html
- Remarks
- Removes the specified range of characters from content of the node and shifts any remaining text downward. if the characters
are successfully deleted, updates the properties of the node to indicate the new content and size.
- Throws
-
- Raises a NO_MODIFICATION_ALLOWED error if the node is read-only.
- Raises an INDEX_SIZE_ERR error if either the offset or count is negative or if offset is greater than the length of the Text
or Comment.
- See Also
-
CharacterData.appendData|CharacterData.insertData|CharacterData.replaceData
- Availability
-
HTML DOM Level 2|W3C
|
Inserts the supplied text at the indicated character offset
|
Show Details |
6.0+ |
1.0+ |
no |
7.0+ |
1.0+ |
Parameters
Number |
offset |
Character offset inside the content at which to insert the new string. |
String |
arg |
String to insert. |
Returns
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/data.html
- Remarks
- Performs the opposite of
deleteData .
- Throws
-
- Raises a NO_MODIFICATION_ALLOWED error if the node is read-only.
- Raises an INDEX_SIZE_ERR if either the offset or count is negative or if offset is greater than the length of the Text or
Comment.
- See Also
-
CharacterData.appendData|CharacterData.deleteData|CharacterData.replaceData
- Availability
-
HTML DOM Level 2|W3C
|
replaceData( Number offset, Number count, String arg) : void
Substitutes the indicated range of text with the supplied string
|
Show Details |
6.0+ |
1.0+ |
no |
8.0+ |
1.0+ |
Parameters
Number |
offset |
Character offset inside the content at which to start the replacement. |
Number |
count |
Number of characters to replace. If the range of characters is greater than the length of the content of the node, all characters
from offset to the end of the string are replaced.
|
String |
arg |
Text string to replace the specified range. |
Returns
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/data.html
- Remarks
- Replaces a specific range of text within the content of the node with the supplied string. Equivilant to invoking
deleteData ,
followed by insertData using the same offset .
- Throws
-
- Raises a NO_MODIFICATION_ALLOWED error if the node is read-only.
- Raises an INDEX_SIZE_ERR error if either the offset or count is negative or if offset is greater than the length of the Text
or Comment.
- See Also
-
CharacterData.appendData|CharacterData.deleteData|CharacterData.insertData
- Availability
-
HTML DOM Level 2|W3C
|
Functions
Splits this node into two adjacent nodes at the given offset
|
Show Details |
6.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
Parameters
Number |
offset |
Number of characters from the beginning of the text string to split the node. |
Returns
-
Using splitText/* Given the source XML, bold the word "everything":
Life, the universe, and everything
*/
var element = document.Document.getElementById('title');
var textNode1 = element.Node.childNodes[0];
if (textNode1.Node.nodeType == Node.Node.TEXT_NODE) {
var offset = textNode1.CharacterData.data.String.indexOf('everything');
var textNode2 = textNode1.splitText(offset);
var boldElement = element.Node.appendChild(document.Document.createElement('b'));
boldElement.Node.appendChild(textNode2);
}
For more examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/splittext.html
- Remarks
-
This method is used to split a Text node into two halves, split on a specific
character offset. The second half of the text is returned as a new Text node,
and is automatically inserted adjacent to the first one in the DOM tree. This method results in
no visual change, except the text nodes can be modified to change the structure of the text (e.g.
wrapping a block of text in another element, like an HTML "bold" tag).
Manipulating text content is possible by using some of the methods on the CharacterData
object, but this is usually more work than developers want to go through. This method provides a
convenience method for a common pattern in manipulating DOM text.
- Throws
-
- Raises an INDEX_SIZE_ERR error if the offset supplied to this method is negative or is greater than the number
of characters in this node.
- Raises a NO_MODIFICATION_ALLOWED_ERR error if this node is read-only.
- See Also
-
Node.normalize
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Remarks
This object interface represents the text contents, or character data, of an Element
or
Attr
object.
If an Element
only has text and no other elements as its children,
then there will be a single Text
node representing all this content. Assuming there are other elements
as it's children however, there will be multiple Text
nodes separating the Element
objects from each other. It is also possible for multiple Text
nodes to be adjacent to one another,
though when the document is saved (or when the parent Node
's Node.normalize method is
invoked) these multiple Text
nodes will be merged into one.
References
CharacterData|Node.normalize
Availability
HTML DOM Level 1|HTML DOM Level 2|W3C