DOM Flashcards
Why do we log things to the console?
To test we have the correct data and keep track of where we are, in regards to the script
What is a “model”?
A representation of an original thing
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 objects within the document
What is a DOM Tree?
The representation of the HTML with all the children and their descendants within the elements.
Give two examples of document methods that retrieve a single element from the DOM.
document. queryselector(“CSS selector”);
document. getElementByID(“ID name”);
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.querySelectorAll(“CSS selector”);
Why might you want to assign the return value of a DOM query to a variable?
If we need the item repeatedly, we can store the value to help reduce the work it needs to do.
Querying an object takes a good amount of work for your computer
What console method allows you to inspect the properties of a DOM element object?
console.dir(object);
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
The elements need to have loaded into the page before they are manipulated by our script
Most scripts (HTML, CSS, JS) are read from top to bottom.
What does document.querySelector() take as its argument and what does it return?
It takes a CSS selector as its argument and returns the while item w/ its content
<h1>Title<h1>
It returns the first item matching that description, from top down</h1></h1>
What does document.querySelectorAll() take as its argument and what does it return?
A CSS selector and it returns a list of all the nodes that meet the specification
It returns an list of all the nodes we asked, and all their additional details from .dir
What is the purpose of events and event handling?
Events allow us to determine when something occurs, like a user interacting with our page or something in the HTML changing with DOM
Handling the events would mean we have a response to the event we are now listening for. In the form of a function, with whatever commands we need
What method of element objects lets you set up a function to be called when a specific type of event occurs?
.addEventListener
element.addEventListener(‘event’, functionName);
What is a callback function?
When we use a function as an argument for another function
function getFullName (first, last) { var fullName = first + ' ' + last; return fullName; }
function greet(getFullName('John', 'Doe')) { console.log('Welcome to the program ' + getFullName) }