JavaScript DOM Manipulation

Assess how well you can interact with and modify the Document Object Model.

1. Which method is used to select an HTML element by its ID?
2. Which of the following methods return a live HTMLCollection?
3. document.querySelector() can select elements by class name using the '.' syntax (e.g., '.my-class').
4. What method is used to attach an event handler function to an element?
5. Which property is used to safely set or retrieve the text content of an element without parsing HTML?
6. Which methods are used to modify an element's attributes?
7. addEventListener() allows multiple event handlers to be attached to the same element for the same event type.
8. What method is used to remove an event listener from an element?
9. Which method is used to create a new DOM element?
10. Which properties provide access to an element's child nodes?
11. Using innerHTML is safer than textContent when inserting user-provided content to prevent XSS attacks.
12. What property returns the parent node of a given element?
13. In event propagation, which phase occurs first when an event is triggered on a child element?
14. Which methods can be used to add a new element to the DOM?
15. event.preventDefault() stops the event from bubbling up the DOM tree.
16. What method is used to remove a child node from its parent element?
17. What does the classList property of a DOM element return?
18. Which of the following are valid DOM event types?
19. The document object in JavaScript represents the entire HTML document.
20. What property is used to set the HTML content of an element (including tags)?
Answered 0 of 0 — 0 correct