Changing Content

innerHTML and textContent

Lesson 53
+25 XP
Step 1 of 5

Changing Text with textContent

The textContent property lets you get or set the text inside an element. It's the safest way to work with plain text!

// HTML:
<p id="message">Hello World!</p>

// Get the text
let text = document.getElementById("message").textContent;
console.log(text); // "Hello World!"

// Set new text
document.getElementById("message").textContent = "Welcome!";

Try It:

Original Text