DOM(Document Object Model) Flashcards
Why do we log things to the console?
SO we can see what’s going on. Better than guessing.
What is a “model”?
Representation of something else.
Which “document” is being referred to in the phrase Document Object Model?
For this one HTML, API
What is the word “object” referring to in the phrase Document Object Model?
Each node is an object
attribute nodes or text nodes
What is a DOM Tree?
It can be thought of as a tree with a single parent stem that branches out into several child branches.
Give two examples of document methods that retrieve a single element from the DOM.
document. getElementById()
document. querySelector()
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.queryselectorAll()
Why might you want to assign the return value of a DOM query to a variable?
If we need to work with an element more than once.
What console method allows you to inspect the properties of a DOM element object?
console.dir();
Why would a script 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 css selector as string?
returns the first element that matches a css selector.
What does document.querySelectorAll() take as its argument and what does it return?
NodeList representing a list of the document’s elements that match the specified group of selectors.
Why do we log things to the console?
To check if it’s working.
What is the purpose of events and event handling?
to callback 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?
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?
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
with the handleclick(), it can’t do anything cuz it’s not calling function
What is the className property of element objects?
set or return the value of an element’s class attribute
How do you update the CSS class attribute of an element using JavaScript?
document.queryseletor(css selector).className = string of the class name
What is the textContent property of element objects?
sets or returns the textual content of the specified node, and all its descendants.
How do you update the text within an element using JavaScript?
elemet.textContent = ‘’