The Text
interface represents a text node
in a DOM tree.
To understand what a text node is, consider the following document:
<html lang="en" class="e">
<head>
<title>Aliens?</title>
</head>
<body>
Why yes.
</body>
</html>
In that document, there are five text nodes, with the following contents:
"\n "
(after the <head>
start tag, a newline followed by four spaces)
"Aliens?"
(the contents of the title
element)
"\n "
(after the </head>
end tag, a newline followed by two spaces)
"\n "
(after the <body>
start tag, a newline followed by two spaces)
"\n Why yes.\n \n\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 new Text
node with the parameter as its textual content.
Instance properties
Inherits properties from its parents, CharacterData
, Node
, and EventTarget
.
Text.assignedSlot
Read only
-
Returns a HTMLSlotElement
representing the <slot>
the node is inserted in.
Text.wholeText
Read only
-
Returns a string containing the text of all Text
nodes logically adjacent to this Node
, concatenated in document order.
Instance methods
Inherits methods from its parent, CharacterData
, Node
, and EventTarget
.
-
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 |
29 |
16 |
24 |
No |
16 |
8 |
4.4 |
29 |
24 |
16 |
8 |
2.0 |
Text |
1 |
12 |
1 |
5 |
≤12.1 |
1 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
assignedSlot |
53 |
79 |
63 |
No |
40 |
10 |
53 |
53 |
63 |
41 |
10 |
6.0 |
getBoxQuads |
No |
No |
31 |
No |
No |
No |
No |
No |
No |
No |
No |
No |
splitText |
1Before Chrome 30, the offset parameter was optional.
|
12 |
1 |
5 |
≤12.1Before Opera 17, the offset parameter was optional.
|
1The offset parameter is optional.
|
1Before version 4.4, the offset parameter was optional.
|
18Before Chrome 30, the offset parameter was optional.
|
4 |
≤12.1Before Opera 17, the offset parameter was optional.
|
1The offset parameter is optional.
|
1.0Before Samsung Internet 2.0, the offset parameter was optional.
|
wholeText |
2 |
12 |
3.5 |
9 |
≤12.1 |
4 |
4.4 |
18 |
4 |
≤12.1 |
3.2 |
1.0 |
See also