DOM Flashcards
Why do we log things to the console?
To make sure our code works
What is a “model”?
A representation of an object that is typically smaller than the object that is being modeled
Which “document” is being referred to in the phrase Document Object Model?
The html document being loaded into a browser
What is the word “object” referring to in the phrase Document Object Model?
Each individual elements on the html page (including the document itself)
What is a DOM Tree?
The drawn mapping of the elements of the html page
Give two examples of document methods that retrieve a single element from the DOM.
querySelector(‘css selector’)
getElementById(‘id’)
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll(‘css selector’)
getElementsByClassName(‘class’)
Why might you want to assign the return value of a DOM query to a variable?
Why might you want to assign the return value of a DOM query to a variable?
What console method allows you to inspect the properties of a DOM element object?
console.dir(variableName)
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?
It takes any valid CSS selector as its argument
Returns the first matching element
What does document.querySelectorAll() take as its argument and what does it return?
It takes any valid CSS selector as its argument
Returns all matching elements in a node list
Why do we log things to the console?
To make sure our code works
What is the purpose of events and event handling?
Events are any changes to a document whether it be from user interaction or changes from within the browser.
Event handlers trigger functions depending on the event
What do [] square brackets mean in function and method syntax documentation?
They represent optional arguments
What method of element objects lets you set up a function to be called when a specific type of event occurs?
element.addEventListener(‘event’, callbackFunction);