dom Flashcards
Why do we log things to the console?
to check for bugs and to see what things are
What is a “model”?
representation of something else
Which “document” is being referred to in the phrase Document Object Model?
the document node at the top of the tree
What is the word “object” referring to in the phrase Document Object Model?
each node is an object with methods and properties
What is a DOM Tree?
A diagram showing parent to child and sibling relations between nodes.
Give two examples of document methods that retrieve a single element from the DOM.
.querySelector() and .geElementById()
Give one example of a document method that retrieves multiple elements from the DOM at once.
.getElementsByClassName()
Why might you want to assign the return value of a DOM query to a variable?
so you don’t have to type the method out everytime to get the same DOM query
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 content needs to be written before it can be called by the domquery.
What does document.querySelector() take as its argument and what does it return?
it takes a selector and returns the first element int he document that matches the specified selector
What does document.querySelectorAll() take as its argument and what does it return?
it returns a nodelist that matches a group of selectors.
Why do we log things to the console?
to see what’s happening and know where we are
What is the purpose of events and event handling?
execute code when an event occurs- have user interaction
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
What is a callback function?
function that is passed into another function as an argument which is then invoked inside the outer function to complete an action
What object is passed into an event listener callback when the event fires?
the event
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
target property of the event object- holds element that was interacted with, console log event.target
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
handleclick() will run and what is returned is passed as the argument.
handleclick does not return and just runs when the click event happens
What is the className property of element objects?
it is the class attribute of the element.
How do you update the CSS class attribute of an element using JavaScript?
document.queryselector().className =
What is the textContent property of element objects?
shows the textcontent of the element
How do you update the text within an element using JavaScript?
document.queryselector().textcontent =
Is the event parameter of an event listener callback always useful?
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?
can call the variable at multiple locations and uses
What does the transform property do?
lets you rotate, scale, skew, or translate an element