0Pricing
JavaScript Academy · Lesson

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

  1. Changing Text and HTML Content
  2. Creating and Inserting Elements
  3. Modifying Attributes and Classes
  4. Removing and Replacing Nodes
← Back to JavaScript Academy