CharacterData : Node

Object for accessing and processing character data in the DOM.

Browser/User Agent Support

IEMozillaNetscapeOperaSafariNetscapte
no1.0+no7.0+1.0+no

Constructors

ConstructorIEMozillaNetscapeOperaSafariNetscapte
Object for accessing and processing character data in the DOM.
no1.0+no7.0+1.0+no
 

Properties

PropertyIEMozillaNetscapeOperaSafariNetscapte
Character data of the current node.
no1.0+no7.0+1.0+no
 
Length of the content of the data property or substringData method.
no1.0+no7.0+1.0+no
 

Methods

MethodIEMozillaNetscapeOperaSafariNetscapte
Appends the specified string to the node text.
6.0+1.0+no7.0+1.0+no
 
Deletes the indicated range of text.
6.0+1.0+no7.0+1.0+no
 
Inserts the supplied text at the indicated character offset
6.0+1.0+no7.0+1.0+no
 
Substitutes the indicated range of text with the supplied string
6.0+1.0+no8.0+1.0+no
 
Returns the specified range of text.
6.0+1.0+no7.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

Comment | Text

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

Number length - read only

Length of the content of the data property or substringData method.

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

Method Detail

appendData(String arg) : void

Appends the specified string to the node text.

StringargString to append.

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.

NumberoffsetCharacter offset inside the content from which to start deleting.
NumbercountNumber 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:

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

NumberoffsetCharacter offset inside the content at which to insert the new string.
StringargString to insert.

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

NumberoffsetCharacter offset inside the content at which to start the replacement.
NumbercountNumber 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.
StringargText string to replace the specified range.

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) : static String

Returns the specified range of text.

NumberoffsetThe character offset inside the content to return.
NumbercountThe number of characters to return.

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