DOM Flashcards
Why do we log things to the console?
for debugging or to know what you are working with
What is a “model”?
a representation or recreation of something that isn’t exact
Which “document” is being referred to in the phrase Document Object Model?
the html document
What is the word “object” referring to in the phrase Document Object Model?
data type object
What is a DOM Tree?
any element and holds all the configuration and the sum of all its parts
Give two examples of document methods that retrieve a single element from the DOM.
getElementId(), querySelector()
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
to use the variable and not calling the query function every time you need to use it
What console method allows you to inspect the properties of a DOM element object?
console.dir() or dir method
Why would a
tag need to be placed at the bottom of the HTML content instead of at the top?
to load all the content
What does document.querySelector() take as its argument and what does it return?
it takes a string element with css selector and matches it
What does document.querySelectorAll() take as its argument and what does it return?
it takes a string element with css selector and node lists (collection of nodes)
Why do we log things to the console?
to debug and to know what you are working with
What is the purpose of events and event handling?
something occurred and information gets sent out also for allowing users to interact with the web page
Are all possible parameters required to use a JavaScript 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(), has 2 argument the string containing the event and the second argument is the callback function
What is a callback function?
when you pass a function as a value to another function
What object is passed into an event listener callback when the event fires?
an object with a huge list of properties to describe the event that just occurred
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
the element where the event occurred. log it out or mdn.
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
the first one calls the function as a call back, while the second one calls the function immediately and nothing gets returned