DOM Flashcards
What is the purpose of events and event handling?
To notify code of “interesting changes” that may affect code execution.
Are all possible parameters required to use a JS method or function?
No
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener()
What is a callback function?
A function that is passed into another function as an argument.
What object is passed into an eventListener callback when the event fires?
An event
What is the |event.target|? If you weren’t sure, how would you check?
The target of the event being listened to, and console.log it
What is the |className| property of an element’s object?
Gets and sets the value of the class attribute of the specified element
How do you update the CSS class attribute of an element using JS?
class.add() / class.remove()
What is the |textContent| property of element objects?
Represents the text content of the element
How do you update the text within an element using JS?
element.textContent = ‘content’
Is the |event| parameter of an eventListener callback always useful?
Yes
Does the |document.createElement()| method insert a new element into the page?
No
How do you add an element as a child to another element?
appendChild()
What do you pass as the arguments to the |element.setAttribute()| method?
name of attribute, value of attribute
ex: (‘class’, ‘pokemon’)
What steps do you need to take in order to insert a new element into the page?
Query the DOM for the parent element, then create a new element, then appendChild the new element to the parent element.