DOM Flashcards
Why do we log things to the console?
To check if we got the desired results.
What is a “model”?
An example of something
Which “document” is being referred to in the phrase Document Object Model?
The HTML document / whatever DOCTYPE is being declared
What is the word “object” referring to in the phrase Document Object Model?
- JavaScript objects
- Represents different parts of the page that is loaded
- The document represented as a large object that holds all info about its content
What is a DOM Tree?
The model of the HTML webpage as a tree of objects.
Give two examples of document methods that retrieve a single element from the DOM.
getElementByID: Selects an element by a specified ID
querySelector: CSS selectors
Give one example of a document method that retrieves multiple elements from the DOM at once.
- querySelectorAll
- getElementsByClassName
- getElementsByTagName
Why might you want to assign the return value of a DOM query to a variable?
Saves the browser time looking for the element again. Also makes it easier to reuse.
What console method allows you to inspect the properties of a DOM element object?
console.dir(): Selects an element by specifying the ID
Why would a
tag need to be placed at the bottom of the HTML content instead of at the top?
The browser needs to access all elements of 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 CSS selectors and returns the first element that matches that selector/group of selectors.
What does document.querySelectorAll() take as its argument and what does it return?
It takes CSS selectors and returns a NodeList with a list of the document’s elements that match the specified group of selectors.
What is the purpose of events and event handling?
Events can be selected for event handling to trigger code that responds to users.
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