MDN self-hosted library · e01.org

CharacterData: data property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<!-- This is an HTML comment -->
<output id="result"></output>
js
const comment = document.body.childNodes[1];
const output = document.getElementById("result");

output.value = comment.data;
html
<span>Result: </span>Not set.
js
const span = document.querySelector("span");
const textNode = span.nextSibling;

textNode.data = "This text has been set using 'textNode.data'.";