Selecting Elements by ID
Which method is used to select an element by its unique ID in the DOM?
- getElementByName
- selectById
- getElementById
- getElementsByClassName
- querySelectorAll
Using querySelector for Classes
To select the first element with class 'myClass', which code would you use?
- document.getElementById('.myClass')
- document.selectElement('.myClass')
- document.getElementsByClassName('myClass')[0]
- document.querySelectorAll('myClass')[0]
- document.querySelector('.myClass')
Changing Text Content
If you want to set the text inside a paragraph element to 'Hello World', which property do you change?
- contentText
- value
- htmlText
- innerStyle
- textContent
Updating Element Styles Inline
Which syntax correctly changes a div's background color to blue using JavaScript?
- div.setAttribute('background', 'blue');
- div.css('background-color', 'blue');
- div.style.set('backgroundColor', 'blue');
- div.backgroundColor = 'blue';
- div.style.backgroundColor = 'blue';
Accessing Child Elements
What property retrieves an array-like collection of a parent element's child elements?
- childObjects
- childElements
- getChildNodes
- children
- nodes
Creating a New Element
Which method creates a new u003Cliu003E element in JavaScript?
- createElement('li')
- document.makeElement('li')
- document.newElement('li')
- document.createElement('li')
- document.addElement('li')
Appending Elements to the DOM
What method adds a newly created element to the end of a parent node's child list?
- appendElement
- addChild
- insertChild
- pushChild
- appendChild
Removing Elements From the DOM
Given an element node, which method can you call to remove it from the DOM?
- exclude
- erase
- remove
- delete
- clear
Retrieving Element Value
How do you get the current value from an input text field using JavaScript?
- input.textContent
- input.value
- input.innerValue
- input.contents
- input.getValue
Adding an Event Listener
Which method is used to listen for a 'click' event on a button element?
- addEventListener
- onEvent
- attachEvent
- buttonListener
- listenToEvent
Inner HTML Manipulation
If you want to insert HTML content into a div, which property should you use?
- divHTML
- innerHTML
- htmlInner
- textInner
- outerText
Selecting Multiple Elements
Which method returns a NodeList of all elements matching a CSS selector?
- getElementByTagName
- selectNodes
- queryAllSelector
- getAllElements
- querySelectorAll
Handling Default Event Behavior
Which method cancels the default action of an event inside its handler function?
- event.cancel()
- event.preventDefault()
- event.stopDefault()
- event.stopEvent()
- event.stopPropagation()
Setting Element Attributes
To change the 'src' attribute of an image element by JavaScript, which method would you use?
- setAttribute
- setAttr
- addAttribute
- updateAttribute
- assignAttribute
Removing an Event Listener
What method is used to detach a previously added event listener from a DOM element?
- clearListener
- deleteEventListener
- removeEventListener
- unlisten
- detachListener