DOM Flashcards
Why do we log things to the console?
To double check the code is doing what is intended.
What is a “model”?
The model is called a DOM tree. The tree is stored in the browsers’ memory.
Which “document” is being referred to in the phrase Document Object Model?
The document is the html file.
What is the word “object” referring to in the phrase Document Object Model?
The object represents a different object for each part of the page.
What is a DOM Tree?
A model of the selected element.
Give two examples of document methods that retrieve a single element from the DOM.
querySelector and getElementById
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?
So you can have an access point instead of having to query it every time you need it.
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?
So the js file can parse the entire html content first.
What does document.querySelector() take as its argument and what does it return?
querySelector takes css selectors and the argument and returns the content of that element.
What does document.querySelectorAll() take as its argument and what does it return?
querySelectorAll takes css selectors and returns a node list.
Why do we log things to the console?
To clearly see what our line of code is doing.
What is the purpose of events and event handling?
Events are used to trigger a particular function. Event handlers are steps triggered after the event occurs.
What method of element objects lets you set up a function to be called when a specific type of event occurs?
object.addEventListener.
What is a callback function?
A callback function is a function passed into another function as an argument. It invokes the function inside.
What object is passed into an event listener callback when the event fires?
The type of event, and the function given.
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
If not sure, console log the event.target. MDN has more information. Event.target is a DOM interface implemented by objects that can receive events and may have listeners for them.
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
The snippet with the callback function calls that line of code when its run instead of when the event occurs.