Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
JAVASCRIPT DOM / CHAPTER 04 / Learn / LESSON 03
textContent reads or sets an element's visible text (no HTML tags). For lessons use textContent — not innerHTML (risks and surprises).
Assign: el.textContent = "Rent". Read: const t = el.textContent.
Mini example:
const label = document.querySelector("#label"); label.textContent = "Rent";
Common mistake: expecting textContent to run HTML; or forgetting the assignment (=).
<span id="label">Food</span><span id="keep">ok</span>textContent sets visible text.
Press Run — HTML loads in a sandbox iframe; Stop removes the iframe (also kills infinite loops).
›