Predict textContent Update
Predict Output Easy
Question
If the HTML has `<p id='msg'>Old</p>`, what does the page show after this code runs?
Code
const el = document.getElementById("msg");
el.textContent = "New";
console.log(el.textContent);
Hint
textContent replaces the text content of the element.
Explanation
Setting el.textContent = "New" replaces all text content of the element with "New". The paragraph that showed 'Old' now shows 'New'. Reading el.textContent back returns "New", which is printed to the console.
Related Resources
Related Lessons
- DOM
Learn about textContent.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.