XML DOM CharacterData Object

The CharacterData interface provides common functions for Text and Comment nodes.

Description of CharacterData object

CharacterData is Text and Comment The super interface of nodes. The document does not contain CharacterData nodes, it only contains Text nodes and Comment nodes. However, since these two types of nodes have similar functions, these functions are defined here so that Text and Comment can inherit them.

Note that it is not necessary to use the string operation methods defined by this interface. The data attribute is a plain JavaScript string, and you can use the + operator to perform string concatenation on it, and you can use various methods of the String and RegExp objects.

CharacterData object properties

Property Description IE F O W3C
data The text contained in the node. 6 1 9 Yes
length The number of characters contained in the node. 6 1 9 Yes

CharacterData object methods

Method Description IE F O W3C
appendData() Adds the specified string to the text contained in the node. 6 1 9 Yes
deleteData() Deletes the specified text from the node. 6 1 9 Yes
insertData() Inserts the specified string into the node text at the specified position. 6 1 9 Yes
replaceData() Replaces the specified number of text starting from the specified position with the specified string. 6 1 9 Yes
substringData() Returns a text copy of the specified number of characters starting from the specified position. 6 1 9 Yes

Related pages

XML DOM Reference Manual:Comment object

XML DOM Reference Manual:Text object