CharacterData.data
The data
property of the CharacterData
interface represent the value of the current object's data.
Value
A string with the character information contained in the CharacterData
node.
Example
Note: CharacterData
is an abstract interface.
The examples below use two concrete interfaces implementing it, Text
and Comment
.
Reading a comment using data
<!-- This is an html comment !-->
<output id="Result"></output>
let comment = document.body.childNodes[1];
let output = document.getElementById("Result");
output.value = comment.data;
Setting the content of a text node using data
<span>Result: </span>Not set.
let span = document.getElementsByTagName("span")[0];
let textnode = span.nextSibling;
textnode.data = "This text has been set using textnode.data."
Specifications
Specification |
---|
DOM Standard # dom-characterdata-data |
Browser compatibility
BCD tables only load in the browser
See also
CharacterData.length
returning the length of the data contained in theCharacterData
node.