What does DOM stand for in JavaScript?
A
Document Object Model B
Data Object Mapping C
Dynamic Object Method D
Document Order Map
Analysis & Theory
DOM stands for **Document Object Model**, which represents the structure of HTML and XML documents.
What is the purpose of the DOM in JavaScript?
A
To style HTML elements B
To define object-oriented classes C
To manipulate the structure and content of web pages D
To write server-side scripts
Analysis & Theory
JavaScript uses the DOM to dynamically access and manipulate HTML content.
Which method selects an element by its ID?
A
document.getElementById() B
document.querySelectorAll() C
document.selectElement() D
document.findById()
Analysis & Theory
`getElementById()` selects the first element with the specified ID.
What does `document.querySelector()` return?
A
All matching elements B
An array of elements C
The first matching element D
A string value
Analysis & Theory
`querySelector()` returns the **first** element that matches a CSS selector.
What will this code do?
```js
document.body.style.background = 'yellow';
```
A
Prints background color B
Sets the body's background color to yellow C
Throws an error D
Deletes the body element
Analysis & Theory
It changes the background color of the `body` element to yellow.
Which DOM property gets the inner content of an element?
A
innerHTML B
textContent C
value D
getContent()
Analysis & Theory
`innerHTML` retrieves or sets the HTML content inside an element.
How do you change the text of a paragraph element with ID `demo`?
A
`document.getElementById('demo').innerHTML = 'New Text';` B
`document.demo.text = 'New Text';` C
`document.getElementByClass('demo').textContent = 'New Text';` D
`document.innerHTML('demo') = 'New Text';`
Analysis & Theory
You use `getElementById()` and `innerHTML` to set new content.
Which method adds a new HTML element to the DOM?
A
appendChild() B
createElement() C
getElementById() D
setContent()
Analysis & Theory
`appendChild()` inserts a new node to the DOM tree.
Which object is the entry point to the DOM in JavaScript?
A
window B
body C
document D
HTML
Analysis & Theory
`document` is the main object that gives access to the DOM.
Which of the following is NOT a valid DOM method?
A
getElementById() B
querySelector() C
innerHTML() D
createElement()
Analysis & Theory
`innerHTML` is a property, not a method.