THE DOM Flashcards
Why do we log things to the console?
To see a variable’s contents, to see what an element contains when using dom query commands.
What is a “model”?
It is a representation of something else.
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?
The model is made of objects, each object in the model represents a different part of the page in the browser window.
What is a DOM Tree?
A DOM element and all of its DOM child elements and contents.
Give two examples of document methods that retrieve a single element from the DOM.
document.querySelector(), document.getElementById()
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.getElementByClassName(), document.getElementByTagName(), document.querySelectorAll().
Why might you want to assign the return value of a DOM query to a variable?
So you can keep track of an element Node’s location in order to use it multiple times without retrieving it again.
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 browser needs to parse all of the elements before interacting with them
What does document.querySelector() take as its argument and what does it return?
A css selector (tag name, class name, id name) it returns the location of the first of that matching element
What does document.querySelectorAll() take as its argument and what does it return?
Css selector (tag name, class name, id name) and returns all of the elements that match in a node list
What is the purpose of events and event handling?
Do react and trigger events when something is done by the user
What do [] square brackets mean in function and method syntax documentation?
They are optional
What method of element objects lets you set up a function to be called when a specific type of event occurs?
.addEventListener