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 the title element)
  • "\n" (after the </head> end tag, a newline followed by a space)
  • "Why yes.\n" (the contents of the body element)

Each of those text nodes is an object that has the properties and methods documented in this article.

Constructor

Text()

Returns a Text node with the parameter as its textual content.

Properties

Inherits properties from its parent, CharacterData.

Text.assignedSlot Read only

Returns a HTMLSlotElement representing the <slot> the node is inserted in.

Text.wholeText Read only

Returns a DOMString containing the text of all Text nodes logically adjacent to this Node, concatenated in document order.

Methods

Inherits methods from its parent, CharacterData.

Text.getBoxQuads()

Returns a list of DOMQuad objects representing the CSS fragments of the node.

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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
Text
1
12
1
5
Yes
1
Yes
18
4
Yes
1
1.0
Text
28
16
24
No
15
8
Yes
28
24
14
8
2.0
assignedSlot
53
≤18
63
No
40
10.1
53
53
63
41
10.3
6.0
replaceWholeText
1-45
12-79
1-10
9
15-32
4-10.1
≤37-45
18-45
4-10
14-32
3-10.3
1.0-5.0
splitText
1
Before Chrome 30, the offset argument was optional.
12
1
5
Yes
Before Opera 17, the offset argument was optional.
1
The offset argument is optional.
Yes
Before version 4.4, the offset argument was optional.
18
Before Chrome 30, the offset argument was optional.
4
Yes
Before Opera 17, the offset argument was optional.
1
The offset argument is optional.
1.0
Before Samsung Internet 2.0, the offset argument was optional.
wholeText
1
12
3.5
9
Yes
4
Yes
18
4
Yes
3.2
1.0
getBoxQuads
No
No
31
No
No
No
No
No
31
No
No
No

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Text