DEV Community

Vasanth S
Vasanth S

Posted on

What is the DOM in JavaScript?

The DOM (Document Object Model) is a programming interface that makes a website interactive and dynamic by allowing JavaScript to work with HTML and CSS.

The DOM turns your web page into a tree of objects that JavaScript can read, modify, or remove.


Example:

<h1>Hello World</h1>
Enter fullscreen mode Exit fullscreen mode
document.querySelector('h1').textContent = "Hello JavaScript!";
Enter fullscreen mode Exit fullscreen mode

Why DOM is important?

  • Change text, images, and styles
  • Handle user clicks and events
  • Add or remove elements
  • Build dynamic, interactive websites

Top comments (0)