XJavascript.com
Toggle Menu
Home
Online Javascript Compiler
Tutorials
JavaScript Tutorials
TypeScript Tutorials
Blog
All Posts
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?
querySelector
getElementById
getElementsByClassName
getElementsByTagName
2. Which of the following methods return a live HTMLCollection?
getElementsByClassName()
getElementsByTagName()
querySelectorAll()
getElementById()
3. document.querySelector() can select elements by class name using the '.' syntax (e.g., '.my-class').
True
False
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?
innerHTML
textContent
innerText
outerHTML
6. Which methods are used to modify an element's attributes?
setAttribute()
getAttribute()
removeAttribute()
classList.add()
7. addEventListener() allows multiple event handlers to be attached to the same element for the same event type.
True
False
8. What method is used to remove an event listener from an element?
9. Which method is used to create a new DOM element?
createElement()
new Element()
createNode()
appendChild()
10. Which properties provide access to an element's child nodes?
childNodes
children
parentNode
nextSibling
11. Using innerHTML is safer than textContent when inserting user-provided content to prevent XSS attacks.
True
False
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?
Bubbling
Target
Capturing
Delegation
14. Which methods can be used to add a new element to the DOM?
appendChild()
append()
prepend()
insertBefore()
15. event.preventDefault() stops the event from bubbling up the DOM tree.
True
False
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?
A string of class names
An array of class names
A DOMTokenList object
A boolean indicating class presence
18. Which of the following are valid DOM event types?
click
mouseover
submit
keydown
19. The document object in JavaScript represents the entire HTML document.
True
False
20. What property is used to set the HTML content of an element (including tags)?
Reset
Answered 0 of 0 — 0 correct