MDN self-hosted library · e01.org

Node: textContent property

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

html
<div id="divA">This is <span>some</span> text!</div>
js
let text = document.getElementById("divA").textContent;
// The text variable is now: 'This is some text!'
js
document.getElementById("divA").textContent = "This text is different!";
// The HTML for divA is now:
// <div id="divA">This text is different!</div>