JS dom-querying, events, and manipulation Flashcards
Why do we log things to the console?
to double check our work , inspect value
What is a “model”?
model is a replica of something/representation of something
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?
object is a datatype in javascript
What is a DOM Tree?
a javascript object for an html element- including all of its elements, attributes and all of its children
Give two examples of document methods that retrieve a single element from the DOM.
document.querySelector(‘element’)
getElementById(‘#idName’)
* can use querySelector for every thing*
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll(‘element’)
Why might you want to assign the return value of a DOM query to a variable?
in case you need to access that specific element multiple times
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?
browser needs to inspect entire document before javaScript can access them
What does document.querySelector() take as its argument and what does it return?
takes a string and its css selector- return is the first element it finds that matches that selector
What does document.querySelectorAll() take as its argument and what does it return?
takes a string and its css selector and returns a node list of elements that match that selector
Why do we log things to the console?
to double check our work and inspect values
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 passed into another function as an argument,
What object is passed into an event listener callback when the event fires?
an object with properties that contain all the data describing that event
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
where the event occurs (NOT the element that event is attached to)
-console.log and then MDN
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
the first one is being passed a function as an argument, the second one is calling that function and the return of that function is being passed before the event listener even happens
What is the purpose of events and event handling?
keep track of user interaction
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
more complicated
What is the className property of element objects?
shows the class name of the selected element and allows you to set it to a different one (GET or SET)
How do you update the CSS class attribute of an element using JavaScript?
property className
ex) element.className = ‘newClass’
What is the textContent property of element objects?
shows the text content of the selected element and allows you to change it
How do you update the text within an element using JavaScript?
property textContent
ex) element.textContent = ‘newText content’
Is the event parameter of an event listener callback always useful?
no, but most of time it will be