DOM Flashcards
Why do we log things to the console?
To see what is going on, for debugging purposes
What is a “model”?
A representation of something
Which “document” is being referred to in the phrase Document Object Model?
the webpage itself
What is the word “object” referring to in the phrase Document Object Model?
the HTML page
What is a DOM Tree?
The pathways of elements and their children
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?
To prevent repeated queries to the DOM, just reuse the variable
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?
To allow the HTML code to be parsed first, then JavaScript can read them
(The elements need to be put on the DOM first, then moved around with JS)
What does document.querySelector() take as its argument and what does it return?
CSS selector as argument, and returns the location of the element selected
What does document.querySelectorAll() take as its argument and what does it return?
CSS selector as argument, and returns a Node List
Why do we log things to the console?
For debugging, check results of javascript code
What is the purpose of events and event handling?
Listening for user interactions with the page
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?
When a function is passed into anothe function or method
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 element at the point of interaction in the DOM
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
1st one sets handleClick as a callback function. 2nd one calls the function within the arguments, thus passing the return value as the second argument.