What is the DOM?
The browser builds the DOM from the HTML; scripts change the DOM, not the original file.
DOM Manipulation · Exercise 1 of 4
Fifteen multiple-choice questions on the JavaScript DOM: selectors, NodeList vs HTMLCollection, textContent vs innerHTML, attributes vs properties, dataset, event phases, delegation, preventDefault, DocumentFragment, script loading and listener removal. Pick an option to check your answer instantly.
What is the DOM?
The browser builds the DOM from the HTML; scripts change the DOM, not the original file.
What does document.querySelector(".missing") return when no element matches?
querySelector returns null; querySelectorAll returns an empty NodeList.
A comment typed by a user must be shown on the page. Which is safest?
textContent never parses HTML, so script-carrying markup is shown as text, preventing XSS.
Which statement is true?
A live collection updates when the DOM changes; a static NodeList is a snapshot.
What is event delegation?
The parent listener checks event.target (usually with closest) and also covers children added later.
In what order does a click event travel?
Listeners default to the bubbling phase; { capture: true } listens on the way down.
A link's click handler must stop the browser from navigating, while parent listeners should still see the click. What should it call?
preventDefault cancels the navigation without stopping the event from bubbling.
How do you read data-user-id="7" from an element el?
dataset converts dashed names to camelCase, and the value is always a string ("7").
The user types "Ravi" into <input value="Asha">. What do input.value and input.getAttribute("value") return?
The value property is the live state; the attribute is the initial value from the HTML.
Why build 500 list items in a DocumentFragment before adding them to the page?
Appending the fragment moves all its children into the page in a single operation.
Timed online tests with instant scores and explanations.