DOM Flashcards
Why do we log things to the console?
to spot check that our code works and debug it, verification, landmark to see code execute.
What is a “model”?
a representation of something.
Which “document” is being referred to in the phrase Document Object Model?
the HTML document. the entire page.
What is the word “object” referring to in the phrase Document Object Model?
refers to the data type object within javascript.
What is a DOM Tree?
an element plus all of its children and their configuration.
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.
querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
to store the reference/location of the object in the DOM tree (caching). it saves the browser looking through the DOM tree to find the same element again.
What console method allows you to inspect the properties of a DOM element object?
console.dir(object)
Why would a
tag need to be placed at the bottom of the HTML content instead of at the top?
it speeds up page load times by loading the HTML content first before running DOM scripts.
What does document.querySelector() take as its argument and what does it return?
it takes CSS selectors as a string as its argument and returns the first matching element.
What does document.querySelectorAll() take as its argument and what does it return?
it takes CSS selectors as a string as its argument and returns a nodelist of all the elements.
What is the purpose of events and event handling?
to prepare to trigger a function and make the website more interactive
Are all possible parameters required to use a JavaScript method or function?
No, there are optional parameters.
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 callback function is 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?
information about what happens.
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
it holds the element where the information originated from. you can check with console log and find more information on MDN.