Document Object Model Flashcards
Why do we log things to the console?
to check our work
What is a “model”?
a recreation used to recreate the HTML page
Which “document” is being referred to in the phrase Document Object Model?
The document node, which includes the whole html itself
What is the word “object” referring to in the phrase Document Object Model?
it refers to each node being an object itself, which are JS objects
What is a DOM Tree?
a model of a webpage consisting of all of the elements and their nodes from parent elements downwards. A DOM tree can be the whole html page or just a small section of it.
Give two examples of document methods that retrieve a single element from the DOM.
queryselector () and getElementByID
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 refer to it and / or update it later using JavaScript
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?
the browser needs to parse all the elements BEFORE the JS file can access them, so the JS file needs to go on the bottom
What does document.querySelector() take as its argument and what does it return?
it takes in a DOM string and returns an HTML object with the first class/id/name that it finds in your HTML with all its child contents
What does document.querySelectorAll() take as its argument and what does it return?
a DOM string and selectors to match and returns a NODE LIST containing an element object for each element that matches your search query
What is the purpose of events and event handling?
to respond in certain ways, or run certain codes/scripts when a user event happens, such as when they click/type/hover over something
What do [] square brackets mean in function and method syntax documentation?
it means they are optional and can be left out
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 that is passed in as an argument of another function, which will be ran later.
What object is passed into an event listener callback when the event fires?
the function object that was defined prior
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
it means the target that will trigger the event if it was acted on aka it is a reference to the object on which the event was dispatched. event.target gives you all the information about that target. Search MDN for more info if needed.