Beginner JavaScript Interview QuestionsBeginnerConcept
JavaScript · Question 30
What is the DOM, and how does JavaScript interact with a web page through it?
Direct answer
The DOM is the browser's object representation of an HTML document; JavaScript uses DOM APIs to query, create, update, and listen to events on document nodes.
The Document Object Model (DOM) is a Web API, not part of the core ECMAScript language. The browser parses HTML into a tree of objects that scripts can work with.
- Query: document.querySelector() returns the first matching element; querySelectorAll() returns all matches in a static NodeList.
- Update: properties such as textContent, classList, attributes, and styles can change the rendered document.
- Create/remove: createElement(), append(), remove(), and related APIs modify the tree.
- Events: addEventListener() connects user or browser events to JavaScript handlers.