Text
The Text interface represents a text node in a DOM tree.
To understand what a text node is, consider the following document:
<html class="e"><head><title>Aliens?</title></head>
<body>Why yes.
</body></html>
In that document, there are three text nodes, with the following contents:
- "
Aliens?" (the contents of thetitleelement) - "
\n" (after the</head>end tag, a newline followed by a space) - "
Why yes.\n" (the contents of thebodyelement)
Each of those text nodes is an object that has the properties and methods documented in this article.
Constructor
Text()-
Returns a new
Textnode with the parameter as its textual content.
Properties
Inherits properties from its parents, CharacterData, Node, and EventTarget.
Text.assignedSlotRead only-
Returns a
HTMLSlotElementrepresenting the<slot>the node is inserted in. Text.wholeTextRead only-
Returns a
DOMStringcontaining the text of allTextnodes logically adjacent to thisNode, concatenated in document order.
Methods
Inherits methods from its parent, CharacterData, Node, and EventTarget.
Text.replaceWholeText-
Replaces the text of the current node and all logically adjacent nodes with the specified text.
Text.splitText-
Breaks the node into two nodes at a specified offset.
Specifications
| Specification |
|---|
| DOM Standard # interface-text |
Browser compatibility
BCD tables only load in the browser