DOM Text Content
Predict Output Easy
Question
What does this code print?
Code
let el = document.createElement("div");
el.textContent = "Hello";
console.log(el.textContent);
Hint
textContent sets/gets the text content of an element.
Explanation
A div element is created, then textContent sets its text to "Hello". Reading el.textContent returns "Hello". Unlike innerHTML, textContent does not parse HTML tags, making it safer against XSS. The text is set as plain text, so any HTML-like content would be displayed literally.
Related Resources
Related Lessons
- DOM Manipulation
Learn DOM manipulation.
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.