CKTIS / JavaScript
CharacterData.data — reading and changing node data
The CharacterData.data property reads or replaces the textual data of a single node, such as Text or Comment. Assigning null sets an empty string.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
node.data
node.data = valueCharacterData.data is a writable property containing a DOM node's string data. CharacterData is an abstract interface; you use it through concrete types such as Text, Comment, CDATASection, and ProcessingInstruction.
Reading node.data returns the current data. Assigning node.data = value replaces its entire content rather than appending text. The special case is null: it becomes "", not the string "null". For a Comment, the value is the comment data without the comment delimiters.
This is a DOM API, not a feature of ECMAScript itself. MDN marks this property as widely available across browsers since July 2015. The presence of Node.js 24 in a repository does not prove this API is available. The example requires a browser document and uses detached nodes, so it does not change the page.
Examples
const text = document.createTextNode("Hello");
const comment = document.createComment("note");
console.log(text.data);
text.data = "Updated";
console.log(text.data);
console.log(comment.data);
text.data = null;
console.log(JSON.stringify(text.data));Result
Hello Updated note ""
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.