DOM Flashcards
What is a “model”?
A representation or recreation of an original
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?
Refers to a JavaScript object
What is a DOM Tree?
The DOM tree is a model of a web page
Give two examples of document methods that retrieve a single element from the DOM.
- getElementById()
- querySelector() – only use querySelector
Give one example of a document method that retrieves multiple elements from the DOM at once.
- getElementsByClassName()
- getElementsByTagName()
- querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
To save the browser from needing to look up the same elements again if it is intended to be reused.
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?
So the html content can load first
What does document.querySelector() take as its argument and what does it return?
- String argument is a CSS Selector (type, class id)
- Returns the first matching element
What does document.querySelectorAll() take as its argument and what does it return?
- String argument is a CSS Selector (type, class id)
- Returns all matching elements in a node list
How do you query for attributes?
(element + attrtype + attrname)
document.querySelector(‘p#explanation’)
What is the DOM?
Representation of a JavaScript object describing the html document
What is the purpose of events and event handling?
Enable functionality with events on the webpage
Are all possible parameters required to use a JavaScript method or function?
No