DOM Flashcards
Why do we log things to the console?
To check and make sure our output is correct and for debugging
What is a “model”?
A representation or recreation of an object/item
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?
Data type objects in JavaScript
What is a DOM Tree?
An element with all its configuration
The giant DOM tree that contains multiple DOM trees within it
Give two examples of document methods that retrieve a single element from the DOM.
querySelector
getElementByID
Only use querySelector as getElementByID is the old way
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll
Only one you need to use for selecting all elements
Why might you want to assign the return value of a DOM query to a variable?
To store for later use
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?
All the elements load before the script so you will get null if you put the file above
What does document.querySelector() take as its argument and what does it return?
The CSS selector syntax that selects all elements and returns only the first one that matches it
What does document.querySelectorAll() take as its argument and what does it return?
The CSS selector syntax and returns all the elements that match it
What is the purpose of events and event handling?
Event listener listens for the events and handling calls the functions that relate to it
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?
addEventListener
What is a callback function?
Passing function as an argument to another function
What object is passed into an event listener callback when the event fires?
An object filled with properties that describe the event
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
The element where the event occured
What is the event.target?
MDN
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
First one is passing the function as a value and the second one is calling the function right now
What is the className property of element objects?
Gets the current set of class elements and sets the value of the class element