DOM Flashcards
Why do we log things to the console?
To check and debug our code
What is a “model”?
data structure
Which “document” is being referred to in the phrase Document Object Model?
The HTML document/ entire document
What is the word “object” referring to in the phrase Document Object Model?
The objects that make up the Dom tree
What is a DOM Tree?
THE DOM TREE IS A
MODEL OF A WEB PAGE consisting of objects
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.
getElementsByClassName()
getElementsByTagName()
querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
Save it to a variable to save us time to access 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?
The browser needs to parse all of the elements in the HTML page before the JavaScript code can access them.
What does document.querySelector() take as its argument and what does it return?
Takes a CSS selector as an argument and returns the first matching element.
What does document.querySelectorAll() take as its argument and what does it return?
Uses a CSS selector as argument and returns all matching elements.
Why do we log things to the console?
To check and debug our code.
What is the purpose of events and event handling?
Allows you or a user to interact and then respond to events that happen
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?
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?
event object
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
point of interaction ie. mouseclick, target property. mdn
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
the second is excuting a function handleClick