Changing Text and HTML Content
Update content with textContent and innerHTML.
Reading and Writing Text
To change what an element displays, you can set its text or its HTML. The right choice depends on whether you need markup and how much you trust the data.
textContent
textContent gets or sets the raw text of an element. Setting it replaces all children with a single text node and treats input as plain text.
const el = document.querySelector("#status");
el.textContent = "Saved!";All lessons in this course
- Changing Text and HTML Content
- Creating and Inserting Elements
- Modifying Attributes and Classes
- Removing and Replacing Nodes