DOM Flashcards
What does document.querySelectorAll() take as its argument and what does it return?
takes a css selector and returns a node list
What does document.querySelector() take as its argument and what does it return?
takes a css selector and returns a single node
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
so that everything else could load first
What console method allows you to inspect the properties of a DOM element object?
console.dir()
Why might you want to assign the return value of a DOM query to a variable?
you use it frequently
What is the word “object” referring to in the phrase Document Object Model?
objects are what comprise the web page
Which “document” is being referred to in the phrase Document Object Model?
document node
What is a DOM Tree?
dom element with its components it consists of four nodes: document node, element nodes, attribute nodes, and text nodes
Why do we log things to the console?
we log things to the console to know what we are doing and to check that our work is valid
Which “document” is being referred to in the phrase Document Object Model?
html
What is a “model”?
representation of something
Why do we log things to the console?
we log things to the console to know what we are doing and to check that our work is valid
What is the purpose of events and event handling?
user interactivity
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 object is passed into an event listener callback when the event fires?
event object; all of the data that a browser feels is pertinent to that event
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
the target property of the event interface is a reference to the object onto which the event was dispatched
check on mdn
basically, which object was the event acted upon?
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
the first is using a callback function while the second is immediately calling the function
What is the className property of element objects?
the className property 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?
use the className property