DOM Flashcards
What is a “model”?
a representation of something
Which “document” is being referred to in the phrase Document Object Model?
html
What is the word “object” referring to in the phrase Document Object Model?
object data type
What is a DOM Tree?
javascript object for an html element and its children containing attributes and values
Give two examples of document methods that retrieve a single element from the DOM.
querySelector( )
getElementById( )
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll( )
Why might you want to assign the return value of a DOM query to a variable?
to use in the future and easier to find
What console method allows you to inspect the properties of a DOM element object?
console.dir( )
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
HTML content has to load first
What does document.querySelector( ) take as its argument and what does it return?
string that contains CSS selector and returns DOM at first occurrence
What does document.querySelectorAll( ) take as its argument and what does it return?
string that contains CSS selector and returns Node list
What is the purpose of events and event handling?
interactivity
Are all possible parameters required to use a JavaScript method or function?
no, some parameters are optional
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?
function passed as an argument in another function
What object is passed into an event listener callback when the event fires?
object with all the data about
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
element WHERE the event occurred, check on MDN
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
function definition return value of the function call
What is the className property of element objects?
he value of an element’s class attribute
How do you update the CSS class attribute of an element using JavaScript?
object.className = ‘class’
What is the textContent property of element objects?
represents the text content of the node and its descendants
How do you update the text within an element using JavaScript?
object.textContent = ‘text content’