DOM (Document Object Model)
What is DOM?
The DOM stands for Document Object Model.
It is a programming interface that represents a webpage as a structured tree of objects.
Each HTML element (tags, text, attributes, etc.) becomes a “node” in this tree.
How does it work?
When a browser loads an HTML page, it converts everything into a tree-like structure. JavaScript can then access, change, delete, or add parts of that tree.
With the DOM, you can:
- Change text
- Change CSS
- Add or remove elements
- React to events (click, scroll, input, etc.)
- Build interactive/dynamic interfaces
Example:
HTML:
<p id="greeting">Hello</p>
JavaScript:
document.getElementById("greeting").textContent = "Hi!";
What happened?
The DOM allowed JavaScript to find the element with ID greeting and update its text from “Hello” to “Hi!”.
Summary:
The DOM is the internal structure of a webpage that JavaScript uses to manipulate and update content, style, and behavior.