LearnFrenzy
Sign in Take a free test

DOM Manipulation · Exercise 1 of 4

DOM Manipulation DOM Manipulation MCQ

  • 15 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

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.

Question 1 Easy

What is the DOM?

A A live tree of objects representing the page, which JavaScript can read and change
B The HTML source file on the server
C A JavaScript library like jQuery
D The CSS rules of the page
Question page & discussion
Question 2 Easy

What does document.querySelector(".missing") return when no element matches?

A undefined
B null
C An empty NodeList
D It throws an error
Question page & discussion
Question 3 Medium

A comment typed by a user must be shown on the page. Which is safest?

A el.textContent = comment
B el.innerHTML = comment
C el.outerHTML = comment
D document.write(comment)
Question page & discussion
Question 4 Medium

Which statement is true?

A Both return live collections
B Both return arrays
C querySelectorAll is live; getElementsByClassName is static
D getElementsByClassName returns a live HTMLCollection; querySelectorAll returns a static NodeList
Question page & discussion
Question 5 Medium

What is event delegation?

A Passing an event to a Web Worker
B Calling preventDefault on every event
C Handling events of many child elements with one listener on their parent, using bubbling
D Attaching the same listener to each child
Question page & discussion
Question 6 Medium

In what order does a click event travel?

A Bubbling → target → capturing
B Target only
C Capturing only, unless stopPropagation is called
D Capturing (down to the target) → target → bubbling (back up)
Question page & discussion
Question 7 Medium

A link's click handler must stop the browser from navigating, while parent listeners should still see the click. What should it call?

A event.stopPropagation()
B event.stopImmediatePropagation()
C return true
D event.preventDefault()
Question page & discussion
Question 8 Easy

How do you read data-user-id="7" from an element el?

A el.dataset.userId
B el.dataset["user-id"]
C el.data.userId
D el.userId
Question page & discussion
Question 9 Hard

The user types "Ravi" into <input value="Asha">. What do input.value and input.getAttribute("value") return?

A "Ravi" and "Asha"
B "Asha" and "Ravi"
C "Ravi" and "Ravi"
D "Asha" and "Asha"
Question page & discussion
Question 10 Medium

Why build 500 list items in a DocumentFragment before adding them to the page?

A Fragments make elements load from a CDN
B The page is updated once instead of 500 times, avoiding repeated layout work
C Fragments add event listeners automatically
D Elements in a fragment cannot be styled
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links