beginner
Change Element Text
Change the text content of an HTML element.
Learn DOM selection and text manipulation.
📚 Concepts & Theory
textContent
element.textContent = 'New text'; 🎯 Your Challenge
Write code to change the heading text to \"Hello DOM\".
📝 Starter Code
JavaScript
// HTML: <h1 id="title">Original</h1>
function changeText() {
// Your code here
}
Solution
JavaScript
function changeText() {
const heading = document.getElementById('title');
heading.textContent = 'Hello DOM';
}
changeText();
Explanation
Select element and set textContent.
❓ Frequently Asked Questions
textContent is safer, no HTML parsing