DOM and events: Text updates
textContent inserts text rather than parsing HTML, making it the appropriate choice for a plain status message.
Current edit
Understand the pattern
textContent inserts text rather than parsing HTML, making it the appropriate choice for a plain status message.
textContent inserts text rather than parsing HTML, making it the appropriate choice for a plain status message.
Misconceptions to reject
- A string containing code executes automatically when it is assigned.
- A successful element lookup guarantees that the rest of an event handler is correct.
This is a code-inspection lab, not a full JavaScript runtime.
Worked example and expected result
const status = document.querySelector("#status");
const message = "All checks passed";
if (status) { status.textContent = message; }textContent inserts text rather than parsing HTML, making it the appropriate choice for a plain status message.
Explain it
Apply it elsewhere
Keep the momentum.
Complete the lab, then explain and apply the pattern.
Next: DOM and events: Class additionsTry an incident drillAnonymous lesson and mastery progress lasts for this session. Sign in to keep synced lesson XP between sessions; mastery stays device-local. No speed bonus, lost lives, or hint penalties.
Keep learning
- 01DOM and events: Click listenersAn event listener registers behavior for a future event; pass a function rather than its return value.Practice
- 02DOM and events: Class additionsclassList.add adds a class without replacing unrelated classes already on the element.Practice
- 03DOM and events: Class togglesclassList.toggle alternates membership unless given an explicit force boolean.Practice