DOM Flashcards
Why do we log things to the console?
To verify the value, debug, and visualize input and outputs.
What is a “model”?
general representation, copy
Which “document” is being referred to in the phrase Document Object Model?
HTML document
What is the word “object” referring to in the phrase Document Object Model?
JavaScript objects: a data type that can hold values
What is a DOM Tree?
series of objects that make up the HTML document
Give two examples of document methods that retrieve a single element from the DOM.
.querySelector(), 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?
it’s faster and for organizational purposes
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?
so that it loads till the very end
What does document.querySelector() take as its argument and what does it return?
CSS selector and return the first element that matches the pattern
What does document.querySelectorAll() take as its argument and what does it return?
returns a NodeList
Why do we log things to the console?
debugging
What is the purpose of events and event handling?
respond to user events
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?
function definition that is passed on as a value
What object is passed into an event listener callback when the event fires?
the event object
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
The place where the event began
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
one is a callback function and another is a function with no parameter
Does the document.createElement() method insert a new element into the page?
no it creates a new element
How do you add an element as a child to another element?
appendChild
What do you pass as the arguments to the element.setAttribute() method?
name of the attribute and the value of the attribute
What steps do you need to take in order to insert a new element into the page?
get the thing we want to add to and then do create Element