Week 3 Quiz Questions Flashcards
Why do we log things to the console?
Makes sure script is running properly
What is a “model”?
it is a version/ representation of the webpage that is not the original, source file/ code
Which “document” is being referred to in the phrase Document Object Model?
document/ document node represents the entire page in the DOM tree
What is the word “object” referring to in the phrase Document Object Model?
the different objects in nodes in a DOM tree (text content, etc)
What is a DOM Tree?
DOM tree is a representation of the different nodes that make up the DOM
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.
.getElementByClassName(‘class’)
Why might you want to assign the return value of a DOM query to a variable?
we can cache the selection and not have to worry about the browser having to look through the DOM tree– it knows exactly where the element is, if saved to a variable
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 the browser can access and parse out all the code to the webpage before the javascript code can do anything
What does document.querySelector() take as its argument and what does it return?
takes a CSS selector and returns the first instance of that selector
What does document.querySelectorAll() take as its argument and what does it return?
takes a CSS selector and returns all instances of the selector in a nodelist
how should DOM query variables look like?
generally, should start with ‘$’
$variable
What is the purpose of events and event handling?
so that when an action/ event occurs in a webpage there is dynamic code that is executed because of the event
Are all possible parameters required to use a JavaScript method or function?
no, not all need parameters
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 that is passed into another function as an ARGUMENT
What object is passed into an event listener callback when the event fires?
it is the ‘event’ object (the function(event))
event being provided from the element that is being queried
indicates where event is taking place
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
specific element that is being targeted in the event object that executes
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
first one function only executes once the event executes.
second one’s function ‘handleClick() will always run regardless of the event click(when the browser is loaded)
What is the className property of element objects?
allows your to retrieve the class name of an element and/or change the class name
How do you update the CSS class attribute of an element using JavaScript?
use the className property:
object.className = ‘new-class-name’ (no periods)
What is the textContent property of element objects?
you can collect all text content from the specified object with textContent and can also change the text content within (changes the markup as well)
(anything between the tags)
How do you update the text within an element using JavaScript?
element.textContent = ‘new text content’
Is the event parameter of an event listener callback always useful?
not always (like in the dom-manipulation exercise)
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– using a variable to track the number of clicks allows for the variable to change as the clicks change, so trying the assignment without the variable would create extra steps
(would have to query the p tag to get the number and then change it)
Why is storing information about a program in variables better than only storing it in the DOM?
the information in the variable can be used/accessed in other places other than that specific webpage
What does the transform property do?
The transform CSS property lets you rotate, scale, skew, or translate an element. (2d or 3d)
Give four examples of CSS transform functions.
skew, translate, rotate, scale
The transition property is shorthand for what CSS properties?
The transition CSS property is a shorthand property for transition-property, transition-duration, transition-timing-function, and transition-delay.