DOM Flashcards
Why do we log things to the console?
To check that the correct output is being made, debugging, knowing what you’re working with
What is a “model”?
Represents the structure of the document. Recreation, representation
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 data type object in javascript
What is the DOM?
Dom is a javascript object that has been constructed to recreate the content of the HTML document
What is a DOM Tree?
An element and all of its configurations and content represented as an object in the dom.
Give two examples of document methods that retrieve a single element from the DOM.
getElementById() and 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 your script needs to use the same 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?
string of Css selector and returns only the first of the matching elements
What does document.querySelectorAll() take as its argument and what does it return?
Css selector and returns Nodelist(collection of nodes)/ all of those elements that match
Why do we log things to the console?
To see the result of our output, to know what we are working with
What is the purpose of events and event handling?
Event - something that occurred. Listener is waiting and calls event handler. The purpose of events is to react to them through event handling, the next step to do
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(‘name of event as a string’, function you want to run)
What is a callback function?
a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
What object is passed into an event listener callback when the event fires?
An object that has properties to describe the event that occurred
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
Element that triggered the event, where did it begin.
Console log and mdn
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick) - passes the function as a value, a call back, when event occurs
element.addEventListener(‘click’, handleClick()) - runs the function right now and replaces it with return value of undefined. Breaks and will not add event listener
What is the className property of element objects?
Get or set the class attribute of element
How do you update the CSS class attribute of an element using JavaScript?
element.className = ‘ ’;
What is the textContent property of element objects?
get or set the text content of the element