DOM Flashcards
(43 cards)
Why do we log things to the console?
To check if the output is what we expected
What is a “model”?
A recreation of the original.
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?
The Javascript object.
What is a DOM Tree?
Dom node plus all of the elements that make it up.
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.
querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
To reuse the result.
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 the contents can load top to bottom first.
What does document.querySelector() take as its argument and what does it return?
A string of CSS Selector and takes the first element that matches in the document.
What does document.querySelectorAll() take as its argument and what does it return?
String of CSS Selector and returns all elements that match the selector in the node list.
Why do we log things to the console?
To check our output
What is the purpose of events and event handling?
To add user functionality to the webpage.
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 function passed into another function as an argument.
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?
Target is the place the element that we are dealing with originated from.
What is the textContent property of element objects?
Adjust the text within an element
How do you update the text within an element using JavaScript?
Assign new text content to the dom object.
Is the event parameter of an event listener callback always useful?
No.
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
More complicated.
Why is storing information about a program in variables better than only storing it in the DOM?
To make re-usable variables.