CharacterData
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, or ProcessingInstruction, which aren't abstract.
Properties
CharacterData inherits properties from its parent, Node.
CharacterData.data-
Is a
DOMStringrepresenting the textual data contained in this object. -
CharacterData.lengthRead only -
Returns an
unsigned longrepresenting the size of the string contained inCharacterData.data. -
Element.nextElementSiblingRead only -
Returns the
Elementimmediately following the specified one in its parent's children list, ornullif the specified element is the last one in the list. -
Element.previousElementSiblingRead only -
Returns the
Elementimmediately prior to the specified one in its parent's children list, ornullif the specified element is the first one in the list.
Methods
CharacterData inherits methods from its parent, Node.
CharacterData.after()-
Inserts a set of
NodeorDOMStringobjects in the children list of theCharacterData's parent, just after theCharacterDataobject. CharacterData.appendData()-
Appends the given
DOMStringto theCharacterData.datastring; when this method returns,datacontains the concatenatedDOMString. CharacterData.before()-
Inserts a set of
NodeorDOMStringobjects in the children list of theCharacterData's parent, just before theCharacterDataobject. CharacterData.deleteData()-
Removes the specified amount of characters, starting at the specified offset, from the
CharacterData.datastring; when this method returns,datacontains the shortenedDOMString. CharacterData.insertData()-
Inserts the specified characters, at the specified offset, in the
CharacterData.datastring; when this method returns,datacontains the modifiedDOMString. CharacterData.remove()-
Removes the object from its parent children list.
CharacterData.replaceData()-
Replaces the specified amount of characters, starting at the specified offset, with the specified
DOMString; when this method returns,datacontains the modifiedDOMString. CharacterData.replaceWith()-
Replaces the characters in the children list of its parent with a set of
NodeorDOMStringobjects. CharacterData.substringData()-
Returns a
DOMStringcontaining the part ofCharacterData.dataof the specified length and starting at the specified offset.
Specifications
| Specification |
|---|
| DOM Standard (DOM) # interface-characterdata |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
CharacterData |
1 |
12 |
1 |
5 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
after |
54 |
17 |
49 |
No |
39 |
10 |
54 |
54 |
49 |
41 |
10 |
6.0 |
appendData |
1 |
12 |
1 |
6 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
before |
54 |
17 |
49 |
No |
39 |
10 |
54 |
54 |
49 |
41 |
10 |
6.0 |
data |
1 |
12 |
1 |
5 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
deleteData |
1 |
12 |
1 |
6 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
insertData |
1 |
12 |
1 |
6 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
length |
1 |
12 |
1 |
5 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
nextElementSibling |
29 |
17 |
25 |
No |
16 |
9 |
≤37 |
29 |
25 |
16 |
9 |
2.0 |
previousElementSibling |
29 |
17 |
25 |
No |
16 |
9 |
≤37 |
29 |
25 |
16 |
9 |
2.0 |
remove |
24 |
12 |
23 |
No |
15 |
7 |
≤37 |
25 |
23 |
14 |
7 |
1.5 |
replaceData |
1 |
12 |
1 |
6 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
replaceWith |
54 |
17 |
49 |
No |
39 |
10 |
54 |
54 |
49 |
41 |
10 |
6.0 |
substringData |
1 |
12 |
1 |
6 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CharacterData