DOM Quiz - Languages JavaScript
Free practice quiz: DOM (Languages JavaScript). 47 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
This Languages JavaScript practice quiz has 47 multiple-choice questions on DOM, and 47 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.
Start quiz: 47 questions, freeSample questions
Which method is used to select an HTML element by its ID in the DOM?
Show answer
Answer: C. getElementById()
The `getElementById()` method is specifically designed to retrieve a single element from the DOM based on its unique `id` attribute.
What is a 'node' in the context of the DOM?
Show answer
Answer: B. Any part of an HTML document, including elements, text, attributes, and comments
The DOM represents an HTML document as a tree structure where each component (element, text, attribute, etc.) is considered a node.
What is an HTML `data-*` attribute used for?
Show answer
Answer: B. To store custom data private to the page or application.
`data-*` attributes allow you to embed custom data attributes on all HTML elements, which can then be used by JavaScript or CSS.
How do you get the value of a specific attribute, like 'href', from an element?
Show answer
Answer: C. element.getAttribute('href')
The `getAttribute()` method is used to retrieve the value of a specified attribute.
Which method is used to remove a specific attribute from an HTML element?
Show answer
Answer: A. removeAttribute()
The `removeAttribute(name)` method removes the specified attribute from the element.
More questions in this quiz
Answers and explanations are in the full quiz.
- What is the primary role of the Document Object Model (DOM) in JavaScript?
- Which DOM property returns a live HTMLCollection of the child elements of a given element?
- What is the difference between `innerHTML` and `textContent` properties?
- Which method is used to add a new attribute to an HTML element?
- What does the `querySelector()` method return if no matching element is found?
- Which event is fired when the user clicks on an HTML element?
- What is the purpose of the `DOMContentLoaded` event?
- Which of the following correctly inserts a new node before a reference node?
- Which method returns an HTMLCollection of all elements with a given tag name?
- What is the difference between `childNodes` and `children`?
- Which property is used to access the parent node of an element?
- What does `document.createElement('div')` do?
- Which method allows you to select all elements that match a given CSS selector?
- What is the `document.body` property?
- Which event is fired when an input element's value has changed and the element loses focus?
- Which method is used to append a new node to the end of the list of children of a parent node?
- Which property returns the text content of an element, ignoring HTML tags?
- Which method can be used to find all elements matching a CSS selector, returning a static NodeList?
- What is the significance of the `window` object in the DOM?
- Which event fires continuously as the user is typing in an input field?
- What is the purpose of `element.classList`?
- Which method is used to create a text node?
- What does `element.style.propertyName` allow you to do?
- Which of the following is NOT a type of node in the DOM?
- What is the difference between an `HTMLCollection` and a `NodeList` when returned by `getElementsByTagName` or `querySelectorAll` respectively?
- What is the purpose of `document.createComment(text)`?
- Which event is triggered when a user presses a key on the keyboard?
- What does `element.hasChildNodes()` return?
- Which property returns the first element child of a node?
- What is the primary purpose of event listeners in DOM manipulation?
- Which method is used to get the next sibling of a node?
- What does `document.body.appendChild(newElement)` do?
- Which CSS property can be directly manipulated using `element.style` in JavaScript?
- What does `element.cloneNode(deep)` do?
- Which event is typically used to execute JavaScript code after the entire page, including all linked resources (like images), has finished loading?
- What is the main difference between `element.outerHTML` and `element.innerHTML`?
- What does `element.hasAttribute(name)` return?
- Which event handler is fired when the user's mouse pointer moves over an element?
- What is the purpose of `document.createDocumentFragment()`?
- Which of the following properties directly accesses the `id` attribute of an element?
- Which event occurs when the browser window is resized?
- What is the primary function of `document.write()`?