DOM Flashcards
Why do we log things to the console?
to know what the code is doing
What is a “model”?
representation of something;
Which “document” is being referred to in the phrase Document Object Model?
the entire page
What is the word “object” referring to in the phrase Document Object Model?
data types, collection of data
What is a DOM Tree?
all the nodes of the elements
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.
.getElementsByClassName()
Why might you want to assign the return value of a DOM query to a variable?
so the location of the value is saved and JS doesn’t have to find it again
What console method allows you to inspect the properties of a DOM element object?
.dir()
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
HTML needs to load first because JS needs to know what to work with
What does document.querySelector() take as its argument and what does it return?
takes in a CSS selector,
returns the first match of the selector
What does document.querySelectorAll() take as its argument and what does it return?
takes in a CSS selector, returns the all the matches of the selector in a node list
What is the purpose of events and event handling?
user interaction
What do [] square brackets mean in function and method syntax documentation?
they’re optional
What is a callback function?
a function passed into another function as an argument
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
the element that the event handler/listener is applied to
What object is passed into an event listener callback when the event fires?
event name & function ?
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
first - event is fired when clicked
second - event is fired at run time
What is the className property of element objects?
list of strings with all the class names of the element
changes the class name of elements
How do you update the CSS class attribute of an element using JavaScript?
.className
What is the textContent property of element objects?
can change text content in an element
How do you update the text within an element using JavaScript?
.textContent
Is the event parameter of an event listener callback always useful?
no
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