DOM Flashcards
Why do we log things to the console?
verify values to help debug
Which “document” is being referred to in the phrase Document Object Model?
the entire page (html)
Which “document” is being referred to in the phrase Document Object Model?
the entire page (html document)
What is a DOM Tree?
a model of the web page (html doc) as a javascript object
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?
in case you need to work with the element more han once
What console method allows you to inspect the properties of a DOM element object?
console.dir()
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
the rest of the page must be loaded to create an accurate DOM tree
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
the rest of the page must be loaded/created to create an accurate DOM tree
What does document.querySelectorAll() take as its argument and what does it return?
CSS selector; returns all matching element
What does document.querySelectorAll() take as its argument and what does it return?
CSS selector; returns all matching element in the form of a node list
What is the word “object” referring to in the phrase Document Object Model?
a data type in javascript which can hold multiple items
Why do we log things to the console?
check things
What is the purpose of events and event handling?
respond to occurrences
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 definition being passed around as a value to be invoked later
What object is passed into an event listener callback when the event fires?
all possible data the browser feels would be pertinent to the event
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
specifies where the event occurs
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
second snippet would result in an error as no arguments would have been passed in
How do you update the CSS class attribute of an element using JavaScript?
using the .className method
What is the textContent property of element objects?
represents text content of the node
How do you update the text within an element using JavaScript?
get element from dom, then use textContent property to change
Is the event parameter of an event listener callback always useful?
no, event doesn’t always need to be used
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
significantly more complicated
Why is storing information about a program in variables better than only storing it in the DOM?
more readily available in a variable
also easier than searching through the entire DOM