JavaScript DOM Manipulation Fundamentals Quiz Quiz

  1. Selecting Elements by ID

    Which method is used to select an element by its unique ID in the DOM?

    1. getElementByName
    2. selectById
    3. getElementById
    4. getElementsByClassName
    5. querySelectorAll
  2. Using querySelector for Classes

    To select the first element with class 'myClass', which code would you use?

    1. document.getElementById('.myClass')
    2. document.selectElement('.myClass')
    3. document.getElementsByClassName('myClass')[0]
    4. document.querySelectorAll('myClass')[0]
    5. document.querySelector('.myClass')
  3. Changing Text Content

    If you want to set the text inside a paragraph element to 'Hello World', which property do you change?

    1. contentText
    2. value
    3. htmlText
    4. innerStyle
    5. textContent
  4. Updating Element Styles Inline

    Which syntax correctly changes a div's background color to blue using JavaScript?

    1. div.setAttribute('background', 'blue');
    2. div.css('background-color', 'blue');
    3. div.style.set('backgroundColor', 'blue');
    4. div.backgroundColor = 'blue';
    5. div.style.backgroundColor = 'blue';
  5. Accessing Child Elements

    What property retrieves an array-like collection of a parent element's child elements?

    1. childObjects
    2. childElements
    3. getChildNodes
    4. children
    5. nodes
  6. Creating a New Element

    Which method creates a new u003Cliu003E element in JavaScript?

    1. createElement('li')
    2. document.makeElement('li')
    3. document.newElement('li')
    4. document.createElement('li')
    5. document.addElement('li')
  7. Appending Elements to the DOM

    What method adds a newly created element to the end of a parent node's child list?

    1. appendElement
    2. addChild
    3. insertChild
    4. pushChild
    5. appendChild
  8. Removing Elements From the DOM

    Given an element node, which method can you call to remove it from the DOM?

    1. exclude
    2. erase
    3. remove
    4. delete
    5. clear
  9. Retrieving Element Value

    How do you get the current value from an input text field using JavaScript?

    1. input.textContent
    2. input.value
    3. input.innerValue
    4. input.contents
    5. input.getValue
  10. Adding an Event Listener

    Which method is used to listen for a 'click' event on a button element?

    1. addEventListener
    2. onEvent
    3. attachEvent
    4. buttonListener
    5. listenToEvent
  11. Inner HTML Manipulation

    If you want to insert HTML content into a div, which property should you use?

    1. divHTML
    2. innerHTML
    3. htmlInner
    4. textInner
    5. outerText
  12. Selecting Multiple Elements

    Which method returns a NodeList of all elements matching a CSS selector?

    1. getElementByTagName
    2. selectNodes
    3. queryAllSelector
    4. getAllElements
    5. querySelectorAll
  13. Handling Default Event Behavior

    Which method cancels the default action of an event inside its handler function?

    1. event.cancel()
    2. event.preventDefault()
    3. event.stopDefault()
    4. event.stopEvent()
    5. event.stopPropagation()
  14. Setting Element Attributes

    To change the 'src' attribute of an image element by JavaScript, which method would you use?

    1. setAttribute
    2. setAttr
    3. addAttribute
    4. updateAttribute
    5. assignAttribute
  15. Removing an Event Listener

    What method is used to detach a previously added event listener from a DOM element?

    1. clearListener
    2. deleteEventListener
    3. removeEventListener
    4. unlisten
    5. detachListener