Student-friendly HTML, CSS, and JavaScript reference with examples
Gets or sets the text inside an element.
const heading = document.querySelector('h1');
// Set text
heading.textContent = 'Hello World!';
// Get text
const text = heading.textContent;
Use this for headings, paragraphs, divs, buttons, and most elements.