Browser/User Agent Support
| IE | Mozilla | Netscape | Opera | Safari | Netscapte | no | 1.0+ | no | 7.0+ | 1.0+ | no |
|---|
Constructors
| Constructor | IE | Mozilla | Netscape | Opera | Safari | Netscapte |
|---|---|---|---|---|---|---|
Object for accessing and processing character data in the DOM. | no | 1.0+ | no | 7.0+ | 1.0+ | no |
Properties
| Property | IE | Mozilla | Netscape | Opera | Safari | Netscapte |
|---|---|---|---|---|---|---|
Character data of the current node. | no | 1.0+ | no | 7.0+ | 1.0+ | no |
Length of the content of the data property or substringData method. | no | 1.0+ | no | 7.0+ | 1.0+ | no |
Methods
| Method | IE | Mozilla | Netscape | Opera | Safari | Netscapte |
|---|---|---|---|---|---|---|
Appends the specified string to the node text. | 6.0+ | 1.0+ | no | 7.0+ | 1.0+ | no |
Deletes the indicated range of text. | 6.0+ | 1.0+ | no | 7.0+ | 1.0+ | no |
Inserts the supplied text at the indicated character offset | 6.0+ | 1.0+ | no | 7.0+ | 1.0+ | no |
Substitutes the indicated range of text with the supplied string | 6.0+ | 1.0+ | no | 8.0+ | 1.0+ | no |
Returns the specified range of text. | 6.0+ | 1.0+ | no | 7.0+ | 1.3+ | no |
Remarks
CharacterData provides a set of attributes and methods for accessing character data in the DOM. This object is always inherited by other objects that require this functionality, such as Text and CDATASection.
CDATASection methods manipulate text ranges and considers that the content of the node may be larger than the limits of the String object, so CDATASection methods all work with numeric character offsets and text ranges. You should already know the ranges that you will need before invoking these methods.
The content of this node is represented as UTF-16.
References
Availability
HTML DOM Level 2 | W3C
Constructor Detail
CharacterData CharacterData()
Object for accessing and processing character data in the DOM.
- Visibility
- internal
Property Detail
String data
Character data of the current node.
- Remarks
- The
dataproperty does not have a size limitation, butdatais subject to the limitations of the size of aStringobject. If the contentdatais too large, usesubstringDatato retrieve the character data in chunks. - Availability
HTML DOM Level 2 | W3C
Number length - read only
Length of the content of the data property or substringData method.
- Remarks
- Length of the content available from the
dataproperty or thesubstringDatamethod. If the content ofdatais empty, the value oflengthwill be zero. - Availability
HTML DOM Level 2 | W3C
Method Detail
appendData(String arg) : void
Appends the specified string to the node text.
| String | arg | String to append. |
-
For examples, see the quirksmode test page:
- Remarks
- Appends the specified string to the end of the current character data content, which will then be available through the
dataproperty. - Throws
- Raises a NO_MODIFICATION_ALLOWED error if the node is read-only.
- See Also
CharacterData.deleteData | CharacterData.insertData | CharacterData.replaceData
- Availability
HTML DOM Level 2 | W3C
deleteData(Number offset, Number count) : void
Deletes the indicated range of text.
| Number | offset | Character offset inside the content from which to start deleting. |
| Number | count | Number of characters to delete. If the range of characters is greater than the length of the content of the node, then all characters from offset to the end of the string are deleted. |
-
For examples, see the quirksmode test page:
- Remarks
- Removes the specified range of characters from content of the node and shifts any remaining text downward. if the characters are successfully deleted, updates the properties of the node to indicate the new content and size.
- Throws
- Raises a NO_MODIFICATION_ALLOWED error if the node is read-only.
- Raises an INDEX_SIZE_ERR error if either the offset or count is negative or if offset is greater than the length of the Text or Comment.
- See Also
CharacterData.appendData | CharacterData.insertData | CharacterData.replaceData
- Availability
HTML DOM Level 2 | W3C
insertData(Number offset, String arg) : void
Inserts the supplied text at the indicated character offset
| Number | offset | Character offset inside the content at which to insert the new string. |
| String | arg | String to insert. |
-
For examples, see the quirksmode test page:
- Remarks
- Performs the opposite of
deleteData. - Throws
- Raises a NO_MODIFICATION_ALLOWED error if the node is read-only.
- Raises an INDEX_SIZE_ERR if either the offset or count is negative or if offset is greater than the length of the Text or Comment.
- See Also
CharacterData.appendData | CharacterData.deleteData | CharacterData.replaceData
- Availability
HTML DOM Level 2 | W3C
replaceData(Number offset, Number count, String arg) : void
Substitutes the indicated range of text with the supplied string
| Number | offset | Character offset inside the content at which to start the replacement. |
| Number | count | Number of characters to replace. If the range of characters is greater than the length of the content of the node, all characters from offset to the end of the string are replaced. |
| String | arg | Text string to replace the specified range. |
-
For examples, see the quirksmode test page:
- Remarks
- Replaces a specific range of text within the content of the node with the supplied string. Equivilant to invoking
deleteData, followed byinsertDatausing the sameoffset. - Throws
- Raises a NO_MODIFICATION_ALLOWED error if the node is read-only.
- Raises an INDEX_SIZE_ERR error if either the offset or count is negative or if offset is greater than the length of the Text or Comment.
- See Also
CharacterData.appendData | CharacterData.deleteData | CharacterData.insertData
- Availability
HTML DOM Level 2 | W3C
substringData(Number offset, Number count) : static String
Returns the specified range of text.
| Number | offset | The character offset inside the content to return. |
| Number | count | The number of characters to return. |
-
For examples, see the quirksmode test page:
- Remarks
- Often used for extracting easily-processable regions of text, this method extracts a region of text from the node's content and returns it.
- Throws
- Throws a DOMException specifying NO_MODIFICATION_ALLOWED if the node is read-only. Throws an INDEX_SIZE_ERR
- Throws a DOMException specifying INDEX_SIZE_ERR if either the offset or count is negative or if offset is greater than the length of the Text or Comment.
- Availability
HTML DOM Level 2 | W3C
