3/28 - 4/1/2022 Flashcards
Why do we log things to the console?
To keep track of what is going on in our code and for debugging purposes.
What is a “model”?
A representation of a real-world object or some structure.
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?
It is referring to what the DOM is made of, which are objects.
What is a DOM Tree?
It is what the DOM uses to tell the browser how to structure the model of the HTML page in its memory.
Give two examples of document methods that retrieve a single element from the DOM.
getElementById and querySelector
Give one example of a document method that retrieves multiple elements from the DOM at once.
getElementsByClassName
Why might you want to assign the return value of a DOM query to a variable?
You might want to use it later on down the script.
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?
The browser needs to parse all of the elements in the HTML page before the JavaScript code can access them.
What does document.querySelector() take as its argument and what does it return?
It takes a CSS selector and returns the first matching element.
What does document.querySelectorAll() take as its argument and what does it return?
It takes a CSS selector and returns all matching elements.
Why do we log things to the console?
To keep track of what’s going on in our program and for debugging.
What is the purpose of events and event handling?
Events specify what event is occurring in the browser and event handlers handle code when an event is triggered or fired.
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?
A function passed into another function as an argument.
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?
The node that is selected by the access method (querySelector or getElementByID).
You could check by checking the console. And you could get more information by google searching it and looking it up on MDN.
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
The first line is listening for the event and waiting before calling the function by omitting the parentheses after the function name “handleClick”.
The second line is calling the function without listening for the ‘click’ event by including the parentheses after ‘handleClick’. So this line would run the function as the page loads, regardless of the event happening or not.
What is the className property of element objects?
The className property of an element object 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?
Use the className property of the targeted class and assign it the updated value.
Ex: var $hotButton = document.querySelector(‘.hot-button’);
$hotButton.className = ‘not-button’;
What is the textContent property of element objects?
The textContent property of the Node interface represents the text content of the Node and its descendants.
How do you update the text within an element using JavaScript?
Use the textContent property of the targeted node; and assign it the updated value.
Ex: var $clickCount = document.querySelector(‘.click-count’);
$clickCount.textContent = ‘some text’;
Is the event parameter of an event listener callback always useful?
No
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?
Because it saves the extra time of having to search through the DOM every time we need the same information.
What does the transform property do?
It lets you scale, rotate, skew or translate an element. It modifies the coordinate space of the CSS visual formatting model.
Give four examples of CSS transform functions.
translate, scale, rotate, skew