JavaScript - DOM Flashcards
Why do we log things to the console?
To see the values of the elements we’re accessing
What is a “model”?
representation of the actual thing, but not actually it
Which “document” is being referred to in the phrase Document Object Model?
It represents the entire HTML page
What is the word “object” referring to in the phrase Document Object Model?
Each node of the DOM Tree, which has methods and properties
What is a DOM Tree?
object modeling the document
any element within the DOM and all of its child contents
Give two examples of document methods that retrieve a single element from the DOM.
getElementByID()
querySelector() - this is the one to use
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?
to reuse it
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?
to make sure all the contents can load first
What does document.querySelector() take as its argument and what does it return?
it takes a string of the selector type element
returns first element that matches the argument
What does document.querySelectorAll() take as its argument and what does it return?
takes a string of the selector type element
returns a NodeList of all elements that match the argument
Why do we log things to the console?
To see the values of the elements we’re accessing as a visual response
What is the purpose of events and event handling?
allows us to interact with the webpage
Are all possible parameters required to use a JavaScript method or function?
no
addEventListener takes functions without parentheses
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 passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action
What object is passed into an event listener callback when the event fires?
The function for the event
What is the event.target ? If you weren’t sure, how would you check? Where could you get more information about it?
the element where the event occurred. Look at MDN for more info.
The element you applied event listener to
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
First one is a variable, second is a function being called (which isn’t good)
What is the className property of element objects?
used to update the value of the class attribute of whatever that element is retrieve the current value or assign
How do you update the CSS class attribute of an element using JavaScript?
assign a new value to the className property on that element