Object: CharacterData
The CharacterData object extends the Node object and can be used to access character data in the DOM. No DOM objects directly correspond to CharacterData; rather, the methods and properties are always inherited by other objects that require this functionality, such as Comment, Text, and CDATASection.
The content of this node is represented as UTF-16. CharacterData methods all work with numeric character offsets and text ranges, and manipulate ranges of text as a sequence of 16-bit units. Before invoking these methods, you should already know the ranges that you are manipulating.
CharacterData properties
Property name |
Type |
Description |
Status |
Availability |
|---|---|---|---|---|
data |
String |
Specifies the character data of the current node. |
writable |
4.6 or later |
length |
int |
Returns the length of the content of the data property or the CharacterData.substringData() method. |
read only |
4.6 or later |
CharacterData methods
Method name |
Description |
Availability |
|---|---|---|
Appends the given string to the end of the data of the node. |
4.6 or later |
|
Removes the specified range of data. |
4.6 or later |
|
Inserts a string at the specified location in the data. |
4.6 or later |
|
Replaces the specified range of data with the given string. |
4.6 or later |
|
Returns the specified range of data from the node. |
4.6 or later |
Method: CharacterData.appendData()
Exceptions
Exception |
Description |
|---|---|
NO_MODIFICATION_ALLOWED_ERR |
This error is thrown if the Node is read only. |
Method: CharacterData.deleteData()
Exceptions
Exception |
Description |
|---|---|
INDEX_SIZE_ERR |
This error is thrown if offset is negative, or is greater than the number of 16-bit units in the data. |
NO_MODIFICATION_ALLOWED_ERR |
This error is thrown if the Node is read only. |
Method: CharacterData.insertData()
Exceptions
Exception |
Description |
|---|---|
INDEX_SIZE_ERR |
This error is thrown if offset is negative, or is greater than the number of 16-bit units in the data. |
NO_MODIFICATION_ALLOWED_ERR |
This error is thrown if the Node is read only. |
Method: CharacterData.replaceData()
Parameters
Parameter |
Type |
Description |
|---|---|---|
offset |
int |
The offset position from which to start replacing. |
count |
int |
The number of 16-bit units to replace. If the sum of offset and count exceeds the length of the data, then all 16-bit units from the offset to the end of the data are replaced. |
arg |
String |
The string with which to replace to the data. |
Exceptions
Exception |
Description |
|---|---|
INDEX_SIZE_ERR |
This error is thrown if offset is negative, or is greater than the number of 16-bit units in the data. |
NO_MODIFICATION_ALLOWED_ERR |
This error is thrown if the Node is read only. |
Method: CharacterData.substringData()
Exceptions
Exception |
Description |
|---|---|
INDEX_SIZE_ERR |
This error is thrown if offset is negative, or is greater than the number of 16-bit units in the data. |
NO_MODIFICATION_ALLOWED_ERR |
This error is thrown if the Node is read only. |