codegurukool.com · Free coding tutorials & online compiler

Home › JavaScript Tutorial › The DOM

The DOM

Change the page from JavaScript.

The DOM is the live tree of the page. Select an element, then change its text, style or attributes.

Example code

<h2 id="h">Hello</h2>
<script>
  const h = document.getElementById("h");
  h.textContent = "Changed by JavaScript";
  h.style.color = "tomato";
</script>

Run this code in the online editor

← FunctionsEvents →