Don't forget to hit the ⭐ if you like this repo.
Please answer the following 50 multiple-choice questions to test your knowledge in JavaScript DOM. You must place your answer file in the submission folder. Within the submission/Q1/set_a folder, create a folder called your github_id.
-
What does DOM stand for?
- a) Document Object Model
- b) Document Oriented Markup
- c) Data Object Model
- d) Data Oriented Markup
-
Which object represents the entire HTML document in the DOM?
- a)
window - b)
document - c)
html - d)
body
- a)
-
Which method is used to select an element by its ID in the DOM?
- a)
getElementById() - b)
getElementsByClassName() - c)
querySelectorAll() - d)
querySelector()
- a)
-
How do you create a new element in the DOM?
- a)
document.createElement() - b)
document.newElement() - c)
document.addNewElement() - d)
document.makeElement()
- a)
-
How do you append a new child element to an existing element in the DOM?
- a)
appendChild() - b)
addChildElement() - c)
addNewElement() - d)
createChildElement()
- a)
-
Which property is used to access the text content of an element in the DOM?
- a)
textContent - b)
innerText - c)
innerHTML - d)
text
- a)
-
How do you add a CSS class to an element in the DOM?
- a)
classList.add() - b)
element.addClass() - c)
element.setAttribute() - d)
element.addCSSClass()
- a)
-
How do you remove a CSS class from an element in the DOM?
- a)
classList.remove() - b)
element.removeClass() - c)
element.removeAttribute() - d)
element.removeCSSClass()
- a)
-
Which method is used to add an event listener to an element in the DOM?
- a)
addEventListener() - b)
attachEvent() - c)
addEvent() - d)
onEvent()
- a)
-
What does the
event.preventDefault()method do?- a) Prevents the default behavior of an event
- b) Stops the propagation of an event
- c) Removes an event listener
- d) Executes the default behavior of an event
-
How do you access the parent element of an element in the DOM?
- a)
parentElement - b)
parentNode - c)
parent() - d)
getParentElement()
- a)
-
How do you remove an element from the DOM?
- a)
remove() - b)
removeElement() - c)
delete() - d)
deleteElement()
- a)
-
Which property is used to access the value of an input field in the DOM?
- a)
value - b)
text - c)
innerHTML - d)
textContent
- a)
-
How do you change the CSS style of an element in the DOM?
- a) Access the
styleproperty of the element - b) Use the
addClass()method - c) Use the
setAttribute()method - d) Use the
changeStyle()method
- a) Access the
-
How do you check if an element has a particular CSS class in the DOM?
- a)
classList.contains() - b)
element.hasClass() - c)
element.hasAttribute() - d)
element.containsCSSClass()
- a)
-
Which method is used to select multiple elements by their class name in the DOM?
- a)
getElementsByClassName() - b)
querySelectorAll() - c)
querySelector() - d)
getElementByClass()
- a)
-
What is the purpose of the
innerHTMLproperty in the DOM?- a) It sets or gets the HTML content of an element
- b) It sets or gets the text content of an element
- c) It sets or gets the CSS style of an element
- d) It sets or gets the value of an input field
-
How do you change the attribute value of an element in the DOM?
- a) Use the
setAttribute()method - b) Use the
changeAttribute()method - c) Use the
updateAttribute()method - d) Use the
attributeValue()method
- a) Use the
-
Which method is used to insert an element before another element in the DOM?
- a)
insertBefore() - b)
insertElement() - c)
appendChild() - d)
addBeforeElement()
- a)
-
What is the purpose of the
querySelectorAll()method in the DOM?- a) It selects and returns the first element that matches a specified CSS selector
- b) It selects and returns all elements that match a specified CSS selector
- c) It selects and returns the elements based on their class names
- d) It selects and returns the elements based on their IDs
-
How do you create a text node in the DOM?
- a)
document.createTextNode() - b)
document.createText() - c)
document.newText() - d)
document.makeTextNode()
- a)
-
Which method is used to replace an element with another element in the DOM?
- a)
replaceChild() - b)
replaceElement() - c)
swapChild() - d)
switchElement()
- a)
-
How do you access the first child element of an element in the DOM?
- a)
firstChild - b)
firstElementChild - c)
childElement - d)
getChildElement()
- a)
-
What does the
event.stopPropagation()method do?- a) Stops the propagation of an event
- b) Prevents the default behavior of an event
- c) Adds an event listener
- d) Executes the default behavior of an event
-
How do you check if an element has a particular attribute in the DOM?
- a)
hasAttribute() - b)
attributeExists() - c)
checkAttribute() - d)
attributePresent()
- a)
-
How do you select the last child element of an element in the DOM?
- a)
lastChild - b)
lastElementChild - c)
childElement - d)
getChildElement()
- a)
-
What is the purpose of the
innerTextproperty in the DOM?- a) It sets or gets the HTML content of an element
- b) It sets or gets the text content of an element
- c) It sets or gets the CSS style of an element
- d) It sets or gets the value of an input field
-
How do you remove all child elements of an element in the DOM?
- a)
innerHTML = "" - b)
removeAllChildren() - c)
removeChildElements() - d)
deleteChildren()
- a)
-
Which method is used to clone an element in the DOM?
- a)
cloneNode() - b)
duplicateNode() - c)
copyElement() - d)
createClone()
- a)
-
How do you access the next sibling element of an element in the DOM?
- a)
nextSibling - b)
nextElementSibling - c)
siblingElement - d)
getNextElementSibling()
- a)
-
What is the purpose of the
offsetWidthproperty in the DOM?- a) It returns the width of an element including padding, border, and scrollbar (if any)
- b) It returns the width of an element excluding padding, border, and scrollbar (if any)
- c) It returns the height of an element including padding, border, and scrollbar (if any)
- d) It returns the height of an element excluding padding, border, and scrollbar (if any)
-
How do you check if an element has any child elements in the DOM?
- a)
hasChildNodes() - b)
hasChildren() - c)
checkChildren() - d)
childNodesExist()
- a)
-
Which method is used to scroll an element into view in the DOM?
- a)
scrollIntoView() - b)
scrollTo() - c)
scrollBy() - d)
elementScroll()
- a)
-
How do you access the previous sibling element of an element in the DOM?
- a)
previousSibling - b)
previousElementSibling - c)
siblingElement - d)
getPreviousElementSibling()
- a)
-
What is the purpose of the
offsetHeightproperty in the DOM?- a) It returns the height of an element including padding, border, and scrollbar (if any)
- b) It returns the height of an element excluding padding, border, and scrollbar (if any)
- c) It returns the width of an element including padding, border, and scrollbar (if any)
- d) It returns the width of an element excluding padding, border, and scrollbar (if any)
-
How do you check if an element is hidden in the DOM?
- a)
element.hidden - b)
element.isVisible() - c)
element.isHidden() - d)
element.display
- a)
-
Which method is used to determine the position of an element relative to the viewport in the DOM?
- a)
getBoundingClientRect() - b)
getPosition() - c)
calculatePosition() - d)
elementPosition()
- a)
-
How do you access the closest ancestor element that matches a specified selector in the DOM?
- a)
closest() - b)
findClosest() - c)
getAncestor() - d)
ancestorElement()
- a)
-
What is the purpose of the
clientWidthproperty in the DOM?- a) It returns the width of an element including padding but excluding border and scrollbar (if any)
- b) It returns the width of an element excluding padding, border, and scrollbar (if any)
- c) It returns the width of an element including padding, border, and scrollbar (if any)
- d) It returns the width of an element including padding but excluding border and scrollbar (if any)
-
How do you access the computed CSS styles of an element in the DOM?
- a)
getComputedStyle() - b)
element.getStyle() - c)
element.getStyles() - d)
computeStyles()
- a)
-
Which method is used to check if an element matches a specified CSS selector in the DOM?
- a)
matches() - b)
elementMatches() - c)
matchSelector() - d)
checkSelector()
- a)
-
How do you check if an element has a particular data attribute in the DOM?
- a)
element.hasAttribute() - b)
element.checkDataAttribute() - c)
element.dataAttributeExists() - d)
element.hasDataAttribute()
- a)
-
What is the purpose of the
clientHeightproperty in the DOM?- a) It returns the height of an element including padding but excluding border and scrollbar (if any)
- b) It returns the height of an element excluding padding, border, and scrollbar (if any)
- c) It returns the height of an element including padding, border, and scrollbar (if any)
- d) It returns the height of an element including padding but excluding border and scrollbar (if any)
-
How do you access the computed width of an element including its padding, border, and scrollbar (if any) in the DOM?
- a)
offsetWidth - b)
clientWidth - c)
scrollWidth - d)
computedWidth
- a)
-
Which method is used to check if an element is a descendant of another element in the DOM?
- a)
contains() - b)
elementContains() - c)
isDescendant() - d)
checkDescendant()
- a)
-
How do you access the computed height of an element including its padding, border, and scrollbar (if any) in the DOM?
- a)
offsetHeight - b)
clientHeight - c)
scrollHeight - d)
computedHeight
- a)
-
What is the purpose of the
scrollIntoView()method in the DOM?- a) Scrolls the element into view, making it visible in the viewport
- b) Scrolls the element to a specified position
- c) Scrolls the entire document to a specified position
- d) Scrolls the element to the top of the page
-
How do you check if an element has a particular style property in the DOM?
- a)
element.style.hasOwnProperty() - b)
element.hasStyleProperty() - c)
element.style.containsProperty() - d)
element.style.hasOwnProperty()
- a)
-
What is the purpose of the
scrollHeightproperty in the DOM?- a) It returns the height of an element including its content, padding, and scrollbar (if any)
- b) It returns the height of an element excluding its content, padding, and scrollbar (if any)
- c) It returns the width of an element including its content, padding, and scrollbar (if any)
- d) It returns the width of an element excluding its content, padding, and scrollbar (if any)
-
How do you access the computed value of a CSS property of an element in the DOM?
- a)
getComputedStyle().getPropertyValue() - b)
element.getComputedPropertyValue() - c)
element.computeStyle() - d)
getStyleValue()
- a)
Please create an Issue for any improvements, suggestions or errors in the content.
You can also contact me using Linkedin for any other queries or feedback.