Nearby lessons
3 of 14JavaScript HTML DOM Methods: innerHTML and innerText
📌 What are DOM innerHTML and innerText?
JavaScript provides various methods to interact with HTML elements via the DOM. Two commonly used properties are innerHTML and innerText. These allow developers to access or update the content inside HTML elements.
🟡 innerHTML
innerHTML is used to get or set the HTML content of an element. It includes all HTML tags and renders them as actual elements.
Code Example
PREVIEW READY
🔵 innerText
innerText is used to get or set the visible text of an element. It does not render HTML tags; instead, it treats them as plain text.
Code Example
PREVIEW READY
⚖️ innerHTML vs innerText
Here's a comparison:
- innerHTML interprets and renders HTML tags.
- innerText treats HTML tags as plain text.
🧠 Test Your Knowledge
3 QuestionsProgress: 0 / 3
Keep Going!JavaScript DOM Elements