Week 3 Flashcards
Why do we log things to the console?
To check our work.
What is a “model”?
Data structures that we use to define the shape of our data.
Which “document” is being referred to in the phrase Document Object Model?
HTML document
What is the word “object” referring to in the phrase Document Object Model?
All the objects made in the document
What is a DOM tree?
A model of a Web Page. It stores in the browsers memory and it consists of four main types of nodes.
Give two examples of document methods that retrieve a single element from the DOM.
getElementById(‘id)
querySelector(‘css selector’)
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll(‘css selector’)
Why might you want to assign the return value of a DOM query to a variable?
If your script needs to use the same element(s) more than once. It saves the browser from looking through the DOM tree to find the same element(s) again.
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?
It gives the HTML time to load before any of the JavaScript loads, which can prevent errors, and speed up website response time.
What does document.querySelector() take as its argument and what does it return?
CSS Selector. Returns only the first of the matching elements.
What does document.querySelectorAll() take as its argument and what does it return?
CSS Selector. Returns all of those that match.a
What is the purpose of events and event handling?
To make the page interactive
Are all possible parameters required to use a JavaScript method or function?
Yes
What method of element objects lets you set up a function to be called when a specific type of event occurs?
AddEventListeners
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?
An event object
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
In JavaScript, event.target is a property of an event object that refers to the element that triggered the event. This can be useful for identifying which element an event originated from, which is often necessary when working with event listeners.
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
handleClick in the first code snippet is used as a function reference rather than the return value of the function.
What is the className property of element objects?
Gets and sets the value of the class attribute of the specified element
How do you update the CSS class attribute of an element using JavaScript?
className
What is the textContent property of element objects?
Allows us to access the text and we can also change the text.
How do you update the text within an element using JavaScript?
textContent
Is the event parameter of an event listener callback always useful?
Yes
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
Why is storing information about a program in variables better than only storing it in the DOM?
Faster to retrieve the information if stored. Better to rely on JavaScript rather than DOM.
What does the transform property do?
The transform CSS property lets you rotate, scale, skew, or translate an element.
Give four examples of CSS Transform functions.
Rotate, scale, skew, matrix