Text (W3C DOM Core object)
| Version | Depr. | Parent |
|---|---|---|
| DOM1 | No | CharacterData |
| IE5.5+ | FF1.5+ | SA1.3+ | OP9+ |
|---|---|---|---|
| Partial | Full | Full | Full |
Example
<p>He pumps funk in the cracks and cuts wax with an axe</p>
The example above shows a paragraph containing a single
Text node, with the nodeValue He pumps funk in the cracks and cuts
wax with an axe.
Description
The Text
interface inherits from CharacterData, and represents
the text content (referred to as character data)
inside an Element or Attr node.
When a document is first loaded there will be only one
Text node for each block of text. Operations such as
splitText may divide blocks of text into multiple
sibling Text nodes, as may creating and adding new
Text nodes, but such divisions will not persist
between sessions. The normalize method merges
adjacent nodes to [re]create the load state of a single
Text node for each block of text.
A
Text node cannot have children.
The DOM does not define a size limit for the data in a
Text node, however some implementations do:
- Firefox
- 4K (4096 bytes)
- Opera 9.0
- 32K (32768 bytes)
- Safari 3
- 64K (65536 bytes)
This has a crucial effect on the ability to process and manipulate
text, because browsers can only work with data up to their limit. The
data and nodeValue of a Text node will
only include that much data, and methods such as cloneNode will only be able to clone up to that
limit.
Furthermore, there is no way to retrieve the additional data in
browsers that do have a limit. The DOM specification suggests to use
the substringData method to do this,
implying that the data is there but unreadable; however this is
not the case — as far as the browser is concerned, there is no
more data.
In this Section
- splitText
Break a text node into two nodes, at a specified character offset.
User-contributed notes
There are no comments yet.