Great work learning to select elements! Now let's make those elements actually change what they display on the page.
Once you've selected an element, you can modify its content in two main ways: textContent
and innerHTML
.
Engagement Message
Can you name the two properties that let you change an element's content?
The textContent
property lets you change the text inside an element. It's perfect for updating plain text content safely.
Here's how it works:
element.textContent = "New text here";
This replaces whatever text was inside that element with your new text.
Engagement Message
What do you think happens to the old text?
Let's say you selected a paragraph:
let myParagraph = document.getElementById("intro");
Then you can change its text:
myParagraph.textContent = "Welcome to our site!";
The paragraph will now display "Welcome to our site!" instead of whatever it showed before.
Engagement Message
In your own words, what does textContent
do?
The innerHTML
property is more powerful—it can change both text AND HTML tags inside an element.
