The DOM
The DOM is the page as JavaScript sees it. document.getElementById finds an element, and you can then change its text, style or attributes.
In the editor, the preview page already contains an empty element with id "demo" that you can write into.
Example
const box = document.getElementById("demo");
box.textContent = "Changed by JavaScript";
box.style.color = "darkgreen";
box.style.fontWeight = "bold";Exercise
Change the text of the element.
const box = document.getElementById("demo"); box. = "Hello";
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.