MDN self-hosted library · e01.org

CharacterData

DOM

no runnable cells web-api-interface upstream source

DOM

The CharacterData abstract interface represents a Node object that contains characters. This is an abstract interface, meaning there aren't any objects of type CharacterData: it is implemented by other interfaces like Text, Comment, CDATASection, or ProcessingInstruction, which aren't abstract.

Instance properties

This interface also inherits properties from its parents, Node and EventTarget.

  • CharacterData.data
  • : A string representing the textual data contained in this object.
  • CharacterData.length
  • : Returns a number representing the size of the string contained in the object.
  • CharacterData.nextElementSibling
  • : Returns the first Element that follows this node, and is a sibling.
  • CharacterData.previousElementSibling
  • : Returns the first Element that precedes this node, and is a sibling.

Instance methods

This interface also inherits methods from its parents, Node and EventTarget.

  • CharacterData.after()
  • : Inserts a set of Node objects or strings in the children list of the CharacterData's parent, just after the CharacterData object.
  • CharacterData.appendData()
  • : Appends the given string to the CharacterData.data string; when this method returns, data contains the concatenated string.
  • CharacterData.before()
  • : Inserts a set of Node objects or strings in the children list of the CharacterData's parent, just before the CharacterData object.
  • CharacterData.deleteData()
  • : Removes the specified number of characters, starting at the specified offset, from the CharacterData.data string; when this method returns, data contains the shortened string.
  • CharacterData.insertData()
  • : Inserts the specified characters, at the specified offset, in the CharacterData.data string; when this method returns, data contains the modified string.
  • CharacterData.remove()
  • : Removes the object from its parent children list.
  • CharacterData.replaceData()
  • : Replaces the specified number of characters, starting at the specified offset, with the specified string; when this method returns, data contains the modified string.
  • CharacterData.replaceWith()
  • : Replaces the characters in the children list of its parent with a set of Node objects or strings.
  • CharacterData.substringData()
  • : Returns a string containing the part of CharacterData.data of the specified length and starting at the specified offset.

Specifications

Browser compatibility

See also

  • The DOM overview page.
  • The concrete interfaces implemented it: Text, CDATASection, ProcessingInstruction, and Comment.