DOM Flashcards
Why do we log things to the console?
For debugging and/or making sure things work
What is a “model”?
Layout of the html document as a tree of objects
Which “document” is being referred to in the phrase Document Object Model?
HTML
What is the word “object” referring to in the phrase Document Object Model?
HTML elements as objects
What is a DOM Tree?
The HTML document in the form of a model of objects that looks like a tree
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.querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
So you can access it later
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?
If it was at the top, the website would stop loading until all of the javascript was downloaded
What does document.querySelector() take as its argument and what does it return?
CSS selector as argument
Returns an element object representing the first element in the document that matches the selector
What does document.querySelectorAll() take as its argument and what does it return?
CSS selector as argument
Returns a NodeList containing one element object for each element that matches the selector
What is the purpose of events and event handling?
Handler is called by listener (I write handler)
Are all possible parameters required to use a JavaScript method or function?
No
What method of element objects lets you set up a function to be called when a specific type of event occurs?
Event listener
What is a callback function?
What object is passed into an event listener callback when the event fires?
event
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
Returns the element that triggered the event