DOM Flashcards
What is a “model”?
a tree
Which “document” is being referred to in the phrase Document Object Model?
html file
What is the word “object” referring to in the phrase Document Object Model?
data type objects
What is a DOM Tree?
model structure
Give two examples of document methods that retrieve a single element from the DOM.
.querySelector(), .getElementById()
Give one example of a document method that retrieves multiple elements from the DOM at once.
.querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
for reusability and so you can access other information within the DOM object
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?
so that when the user first load the page, all content can get loaded up first before DOM
What does document.querySelector() take as its argument and what does it return?
string of css selector, return first matched item
What does document.querySelectorAll() take as its argument and what does it return?
string of css selector, return nodeList of all the matched items
What is the purpose of events and event handling?
prepare of incoming actions and response with something (interactive)
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()
What is a callback function?
function that is passed into another function (not calling it)
What object is passed into an event listener callback when the event fires?
event data
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
event target is the element that the event originated from, console log it, MDN
What is the difference between these two snippets of code?
1- element.addEventListener(‘click’, handleClick)
2- element.addEventListener(‘click’, handleClick())
1 - is set with a callback function
2 - the function will run on opening the webpage
what is event bubbling?
event that happen to the element, it happens to the ancestor elements as well
Div > button -> click on button = click on Div
What is the className property of element objects?
value of the attribute class of HTML document
How do you update the CSS class attribute of an element using JavaScript?
element.className = ‘new_value new_value_2’
What is the textContent property of element objects?
property that hold the text for that element
How do you update the text within an element using JavaScript?
element.textContent = ‘new value’
Is the event parameter of an event listener callback always useful?
no