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
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener() method
What is a callback function?
A callback function is 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?
Event object
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
A reference to the object onto which the event was dispatched
Learn more with:
console.dir(event.target)
What is the className property of element objects?
It gets and sets class to an element
How do you update the CSS class attribute of an element using JavaScript?
$element.className = “classone classtwo“
What is the textContent property of element objects?
textContent property allows you to get and set the text inside a node
How do you update the text within an element using JavaScript?
node.textContent = “Assign text value”
Is the event parameter of an event listener callback always useful?
No