DOM Flashcards
Why do we log things to the console?
to debug / check
What is a “model”?
As a browser loads a web page, it creates a model of that page.
Which “document” is being referred to in the phrase Document Object Model?
it represents the entire HTML page (and also corresponds to
the document object)
What is the word “object” referring to in the phrase Document Object Model?
data type object in Javascript
What is a DOM Tree?
every element/content/configuration on your page is represented in the DOM tree
Give two examples of document methods that retrieve a single element from the DOM.
get ElementByld () don’t use
querySelector ()
use
Give one example of a document method that retrieves multiple elements from the DOM at once.
getElementsByClassName() don’t use
getElementsByTagName() don’t use
querySelectorAll() use
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(s) more than once
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?
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?
Uses CSS selector syntax that would select one or more elements .
This method returns only the first of the matching elements.
querySelector(‘li.hot’)
What does document.querySelectorAll() take as its argument and what does it return?
Uses CSS selector syntax to select one or more elements and returns all (node list) of those that match.
querySelectorAll(‘li.hot’)
What is the purpose of events and event handling?
When you browse the web, your browser registers different
types of events. It’s the browser’s way of saying, “Hey, this
just happened.” Your script can then respond to these events.
Are all possible parameters required to use a JavaScript method or function?
checkUsername (} function. Note that the parentheses are omitted
where the function is called because they would indicate that
the function should run as the page loads (rather than when the
event fires)
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?
passing function as a value typically to another function
What object is passed into an event listener callback when the event fires?
object with a huge set of properties explaining what just occurred
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
element where the event occurred
check it in console.log or mdn
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
top: passes function correctly
bottom: calling function immediately and returning event value
What is the className property of element objects?
The className property of the Element interface gets and sets the value of the class attribute of the specified element.
How do you update the CSS class attribute of an element using JavaScript?
element/variable.className = ‘value’
variable = document.querySelector
What is the textContent property of element objects?
The textContent property of the Node interface represents the text content of the node and its descendants.