CharacterData : Node
Return to: HTML DOM Level 2 index

Object for accessing and processing character data in the DOM.

Platform Support

IE Mozilla Netscape Opera Safari Chrome
no 1.0+ no 7.0+ 1.0+ no

Constructors

Constructor Action IE Mozilla Netscape Opera Safari Chrome
CharacterData Constructor() : CharacterData
Object for accessing and processing character data in the DOM.
Show Details no 1.0+ no 7.0+ 1.0+ no

CharacterData() : CharacterData

Object for accessing and processing character data in the DOM.

Returns
CharacterData

Visibility
internal

Properties

Property Action IE Mozilla Netscape Opera Safari Chrome
data : String
Character data of the current node.
Show Details no 1.0+ no 7.0+ 1.0+ no
Remarks
The data property does not have a size limitation, but data is subject to the limitations of the size of a String object. If the content data is too large, use substringData to retrieve the character data in chunks.
Availability

HTML DOM Level 2|W3C

length : Number
Length of the content of the data property or substringData method.
Show Details no 1.0+ no 7.0+ 1.0+ no
Remarks
Length of the content available from the data property or the substringData method. If the content of data is empty, the value of length will be zero.
Availability

HTML DOM Level 2|W3C

Functions

Method Action IE Mozilla Netscape Opera Safari Chrome
appendData(String arg) : void
Appends the specified string to the node text.
Show Details 6.0+ 1.0+ no 7.0+ 1.0+ no

Parameters
String arg String to append.

Returns
void

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/data.html

Remarks
Appends the specified string to the end of the current character data content, which will then be available through the data property.
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.
Show Details 6.0+ 1.0+ no 7.0+ 1.0+ no

Parameters
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.

Returns
void

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/data.html

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
Show Details 6.0+ 1.0+ no 7.0+ 1.0+ no

Parameters
Number offset Character offset inside the content at which to insert the new string.
String arg String to insert.

Returns
void

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/data.html

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
Show Details 6.0+ 1.0+ no 8.0+ 1.0+ no

Parameters
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.

Returns
void

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/data.html

Remarks
Replaces a specific range of text within the content of the node with the supplied string. Equivilant to invoking deleteData, followed by insertData using the same offset.
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) : String
Returns the specified range of text.
Show Details 6.0+ 1.0+ no 7.0+ 1.3+ no

Parameters
Number offset The character offset inside the content to return.
Number count The number of characters to return.

Returns
String

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/data.html

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

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

Comment|Text

Availability

HTML DOM Level 2|W3C

text_javascript aptana_docs