JavaScript Institute DOM Manipulation Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Thames
T
Thames
Community Contributor
Quizzes Created: 11982 | Total Attempts: 187,298
| Attempts: 12 | Questions: 20 | Updated: Aug 15, 2026
Please wait...
Question 1 / 21
🏆 Rank #-- ▾
0 %
0/100
Score 0/100

1. How do you get the value of an attribute using getAttribute()?

Explanation

`getAttribute()` retrieves an HTML element’s attribute by its name. Pass `'data-id'` as the argument to get that attribute’s value from `element`.

Submit
Please wait...
About This Quiz
JavaScript Institute Dom Manipulation Quiz - Quiz

This quiz evaluates your ability to manipulate the Document Object Model (DOM) using JavaScript. Test your knowledge of selecting elements, modifying attributes, handling events, and dynamically updating web page content. Essential skills for building interactive web applications.

2.

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2. Which property contains all child elements (excluding text nodes)?

Explanation

The `children` property returns a collection of an element’s child elements, excluding text nodes and other non-element nodes. By contrast, `childNodes` includes all child nodes, such as text and comments. This makes `children` useful when you need to work only with the element’s HTML descendants directly nested inside it.

Submit

3. What does insertBefore() do?

Explanation

`insertBefore()` adds a new node to a parent element immediately before a specified child node, allowing you to control the order of elements in the document.

Submit

4. What does event.preventDefault() do?

Explanation

`event.preventDefault()` cancels the browser’s normal response to an event, such as following a link or submitting a form. It does not stop the event from propagating to other elements or remove its listener.

Submit

5. How do you select multiple elements with a specific class?

Explanation

`querySelectorAll('.className')` uses the CSS class selector syntax, where the period (`.`) indicates a class. It returns a collection of all elements matching that class. By contrast, `querySelector('.className')` returns only the first match, and `getElementById` selects by ID rather than class.

Submit

6. What does the textContent property do?

Explanation

The `textContent` property retrieves all text inside an element and its descendants, without including any HTML tags. Unlike `innerHTML`, it returns plain text rather than markup.

Submit

7. Which method sets an attribute on an element?

Explanation

`setAttribute()` assigns a value to an element’s attribute, creating the attribute if it does not already exist.

Submit

8. Which method selects a single element by its ID?

Explanation

`getElementById()` retrieves the element whose `id` attribute matches the specified value. Since IDs are intended to be unique within a document, it returns a single element.

Submit

9. How do you attach an event listener to an element?

Explanation

`addEventListener()` is the standard DOM method for registering an event handler. It attaches the callback to the element’s `click` event, so the callback runs when the element is clicked.

Submit

10. Which event fires when a user clicks on an element?

Explanation

The `onclick` event fires when a user clicks an element. By contrast, `onchange` responds to a value change, `onload` fires when a page or resource loads, and hovering over an element is typically handled with `onmouseover`.

Submit

11. What does appendChild() do?

Explanation

In the DOM, `appendChild()` adds a node as the last child of a specified parent element. If the node already exists elsewhere in the document, it is moved to the new parent rather than duplicated.

Submit

12. Which method creates a new DOM element?

Explanation

`createElement()` creates a new HTML element node, such as a `

` or `

`. The new element is not added to the page automatically; it must be inserted into the DOM separately, for example with `appendChild()` or `append()`.

Submit

13. How do you add a CSS class to an element using classList?

Explanation

`classList` provides methods for managing an element’s CSS classes. Use `element.classList.add('className')` to add the specified class. The other options use properties or methods that are not part of the standard DOM API for adding classes.

Submit

14. Which property modifies the HTML content of an element?

Explanation

`innerHTML` gets or sets the HTML markup inside an element. When you assign a value containing tags, the browser parses them and updates the element’s content. By contrast, `textContent` and `innerText` work with text, while `value` is typically used for form controls.

Submit

15. What does the querySelector() method return when no matching element is found?

Explanation

`querySelector()` returns the first element that matches the specified CSS selector. If no element matches, it returns `null`, indicating that no matching element was found.

Submit

16. Which property returns the parent element of a node?

Explanation

In the DOM, `parentElement` returns a node’s parent when that parent is an element, while `parentNode` returns the parent node, which may be an element or another node type. For an element with an element parent, both properties identify that parent, so either can be used to access it.

Submit

17. What does removeChild() do?

Explanation

`removeChild()` removes a specified child node from its parent element. Other child nodes remain unchanged, and the removed node can still be referenced or added elsewhere in the document.

Submit

18. Which method removes all child nodes from an element?

Explanation

Setting an element’s `innerHTML` to an empty string removes all of its child nodes and clears its contents.

Submit

19. Which property accesses the first child node of an element?

Explanation

In the DOM, `firstChild` returns the first child node of an element. The returned node may be an element, text node, or comment, depending on the markup. By contrast, `children[0]` accesses the first child element only, while `firstElement` and `firstNode` are not standard DOM properties.

Submit

20. How do you dynamically change the style of an element?

Explanation

Use the element’s `style` property to change an inline CSS property dynamically. Setting `element.style.color = 'red'` updates the element’s text color to red.

Submit
×
Saved
Thank you for your feedback!
View My Results
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
How do you get the value of an attribute using getAttribute()?
Which property contains all child elements (excluding text nodes)?
What does insertBefore() do?
What does event.preventDefault() do?
How do you select multiple elements with a specific class?
What does the textContent property do?
Which method sets an attribute on an element?
Which method selects a single element by its ID?
How do you attach an event listener to an element?
Which event fires when a user clicks on an element?
What does appendChild() do?
Which method creates a new DOM element?
How do you add a CSS class to an element using classList?
Which property modifies the HTML content of an element?
What does the querySelector() method return when no matching element...
Which property returns the parent element of a node?
What does removeChild() do?
Which method removes all child nodes from an element?
Which property accesses the first child node of an element?
How do you dynamically change the style of an element?
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!