DOM Flashcards
Why do we log things to the console?
so we can check our code for bugs along the way and make sure everything is running without error
What is a “model”?
something you want to mirror or follow
Give two examples of document methods that retrieve a single element from the DOM.
getElementbyId & querySelector
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?
So you can store the reference or location of the element you’re trying to retrieve into the variable so the browser doesn’t have to keep going back to look for the element
What console method allows you to inspect the properties of a DOM element object?
console.dir
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?
javascript objects
What is a DOM Tree?
A model of the page when it loads in a browser in the form of a tree.
Why would a <a>«/a>script<a>></a> tag need to be placed at the bottom of the HTML content instead of at the top?</a>
the content of the HTML page need to be set first before the dom tree is made
What does document.querySelector() take as its argument and what does it return?
takes in a css selector and returns the first element that matches
What does document.querySelectorAll() take as its argument and what does it return?
takes in a css selector and returns a NodeList
What is the purpose of events and event handling?
add dynamic content and interactivity. 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 so it can be invoked later
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?
place where the event actually occurred.
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
top one is just a callback function that’s being passed around as a value. the second one you’re calling the function right then and there
What is the className property of element objects?
gets and sets the value of the class attribute of the specified element
How do you update the CSS class attribute of an element using JavaScript?
get element from DOM, use className property with assignment operator, and new value
What is the textContent property of element objects?
text inside of the element
How do you update the text within an element using JavaScript?
get element from DOM and assignment operator with textContent
Is the event parameter of an event listener callback always useful?
no