- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript DOM Content
JavaScript DOM
JavaScript DOM Content
textContentandinnerHTMLread and change what is inside an element.
textContent treats everything as plain text.
innerHTML treats it as markup, which is powerful but needs care.
Example
Example
javascript
document.body.innerHTML = '<p id="demo">Old</p>';
document.getElementById("demo").textContent = "New";
console.log(document.getElementById("demo").textContent);The output is New.
