Document Object Model Flashcards
Why do we log things to the console?
to trouble shoot
What is a “model”?
a replica of the original
Which “document” is being referred to in the phrase Document Object Model?
the whole html document
What is the word “object” referring to in the phrase Document Object Model?
a collection of a whole bunch of objects from js
What is a DOM Tree?
a model of a web page made of objects
Give two examples of document methods that retrieve a single element from the DOM.
document.queryselector() and getelementbyid
Why might you want to assign the return value of a DOM query to a variable?
because you need to save the elements in variables in order to use dir on them. Or, you have to pass the call to querySelector to the dir method. And because once we select that object we have it saved already in that variable, so if we need to acces it again we can just use the variable instead of having to use the dom again
Why might you want to assign the return value of a DOM query to a variable?
because you need to save the elements in variables in order to use dir on them. Or, you have to pass the call to querySelector to the dir method. And because once we select that object we have it saved already in that variable, so if we need to acces it again we can just use the variable instead of having to call the dom element again
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?
because the html elements needs to load first
What does document.querySelector() take as its argument and what does it return?
a css selector as a string or the element selector as its string and it returns the first one it encounters, or null if theres nothing
What does document.querySelectorAll() take as its argument and what does it return?
a css selector as a string or element and it returns all the elements that match
What is the purpose of events and event handling?
to listen for things like clicks, hover etc
Are all possible parameters required to use a JavaScript method or function?
no,make sure their available as needed, but dont have to use
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 event listener callback when the event fires?
event object
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
it is the element thats was interacted with and mdn
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
first one the second argument is the function and in the second one is going to call the argument automatically and it will ignore the first argument
What is the className property of element objects?
it represent the class attribute of the element
How do you update the CSS class attribute of an element using JavaScript?
using the classname property or classlist since it only adds or removes specific classes
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
more complicated
Why is storing information about a program in variables better than only storing it in the DOM?
its faster when you need to re use it