JavaScriptQuestion 02 of 36
What do you mean by DOM and the importance of it?
Answer out loud or in your head first, then compare.
Answer
The DOM, or Document Object Model, is an object representation of HTML.
HTML:
HTML
<body>
<h1>Hello</h1>
<button>Click</button>
</body>is represented as a tree of objects.
Through the DOM, JavaScript can:
- find an element,
- change its content,
- add or remove an element,
- handle an event,
- change classes or styles.
Example:
JavaScript
const button = document.querySelector("button");
button.addEventListener("click", () => {
button.textContent = "Clicked";
});To be precise:
The DOM is not “the HTML itself”. It's a representation of the document that JavaScript can access.
How did it go? Be honest — “Not yet” puts the question on your review list.