Skip to content

Latest commit

 

History

History
323 lines (265 loc) · 13 KB

n2aq.md

File metadata and controls

323 lines (265 loc) · 13 KB

Stars Badge Forks Badge Pull Requests Badge Issues Badge GitHub contributors Visitors

Don't forget to hit the ⭐ if you like this repo.

JavaScript: DOM

Set A

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.

  1. What does DOM stand for?

    • a) Document Object Model
    • b) Document Oriented Markup
    • c) Data Object Model
    • d) Data Oriented Markup
  2. Which object represents the entire HTML document in the DOM?

    • a) window
    • b) document
    • c) html
    • d) body
  3. Which method is used to select an element by its ID in the DOM?

    • a) getElementById()
    • b) getElementsByClassName()
    • c) querySelectorAll()
    • d) querySelector()
  4. How do you create a new element in the DOM?

    • a) document.createElement()
    • b) document.newElement()
    • c) document.addNewElement()
    • d) document.makeElement()
  5. How do you append a new child element to an existing element in the DOM?

    • a) appendChild()
    • b) addChildElement()
    • c) addNewElement()
    • d) createChildElement()
  6. Which property is used to access the text content of an element in the DOM?

    • a) textContent
    • b) innerText
    • c) innerHTML
    • d) text
  7. 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()
  8. 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()
  9. Which method is used to add an event listener to an element in the DOM?

    • a) addEventListener()
    • b) attachEvent()
    • c) addEvent()
    • d) onEvent()
  10. 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
  11. How do you access the parent element of an element in the DOM?

    • a) parentElement
    • b) parentNode
    • c) parent()
    • d) getParentElement()
  12. How do you remove an element from the DOM?

    • a) remove()
    • b) removeElement()
    • c) delete()
    • d) deleteElement()
  13. Which property is used to access the value of an input field in the DOM?

    • a) value
    • b) text
    • c) innerHTML
    • d) textContent
  14. How do you change the CSS style of an element in the DOM?

    • a) Access the style property of the element
    • b) Use the addClass() method
    • c) Use the setAttribute() method
    • d) Use the changeStyle() method
  15. 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()
  16. Which method is used to select multiple elements by their class name in the DOM?

    • a) getElementsByClassName()
    • b) querySelectorAll()
    • c) querySelector()
    • d) getElementByClass()
  17. What is the purpose of the innerHTML property 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
  18. 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
  19. Which method is used to insert an element before another element in the DOM?

    • a) insertBefore()
    • b) insertElement()
    • c) appendChild()
    • d) addBeforeElement()
  20. 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
  21. How do you create a text node in the DOM?

    • a) document.createTextNode()
    • b) document.createText()
    • c) document.newText()
    • d) document.makeTextNode()
  22. Which method is used to replace an element with another element in the DOM?

    • a) replaceChild()
    • b) replaceElement()
    • c) swapChild()
    • d) switchElement()
  23. How do you access the first child element of an element in the DOM?

    • a) firstChild
    • b) firstElementChild
    • c) childElement
    • d) getChildElement()
  24. 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
  25. How do you check if an element has a particular attribute in the DOM?

    • a) hasAttribute()
    • b) attributeExists()
    • c) checkAttribute()
    • d) attributePresent()
  26. How do you select the last child element of an element in the DOM?

    • a) lastChild
    • b) lastElementChild
    • c) childElement
    • d) getChildElement()
  27. What is the purpose of the innerText property 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
  28. How do you remove all child elements of an element in the DOM?

    • a) innerHTML = ""
    • b) removeAllChildren()
    • c) removeChildElements()
    • d) deleteChildren()
  29. Which method is used to clone an element in the DOM?

    • a) cloneNode()
    • b) duplicateNode()
    • c) copyElement()
    • d) createClone()
  30. How do you access the next sibling element of an element in the DOM?

    • a) nextSibling
    • b) nextElementSibling
    • c) siblingElement
    • d) getNextElementSibling()
  31. What is the purpose of the offsetWidth property 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)
  32. How do you check if an element has any child elements in the DOM?

    • a) hasChildNodes()
    • b) hasChildren()
    • c) checkChildren()
    • d) childNodesExist()
  33. Which method is used to scroll an element into view in the DOM?

    • a) scrollIntoView()
    • b) scrollTo()
    • c) scrollBy()
    • d) elementScroll()
  34. How do you access the previous sibling element of an element in the DOM?

    • a) previousSibling
    • b) previousElementSibling
    • c) siblingElement
    • d) getPreviousElementSibling()
  35. What is the purpose of the offsetHeight property 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)
  36. How do you check if an element is hidden in the DOM?

    • a) element.hidden
    • b) element.isVisible()
    • c) element.isHidden()
    • d) element.display
  37. 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()
  38. How do you access the closest ancestor element that matches a specified selector in the DOM?

    • a) closest()
    • b) findClosest()
    • c) getAncestor()
    • d) ancestorElement()
  39. What is the purpose of the clientWidth property 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)
  40. How do you access the computed CSS styles of an element in the DOM?

    • a) getComputedStyle()
    • b) element.getStyle()
    • c) element.getStyles()
    • d) computeStyles()
  41. 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()
  42. 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()
  43. What is the purpose of the clientHeight property 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)
  44. 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
  45. 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()
  46. 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
  47. 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
  48. 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()
  49. What is the purpose of the scrollHeight property 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)
  50. 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()

Contribution 🛠️

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.

Visitors