DOM 0206 Flashcards
Why do we log things to the console?
so u can see what ur code’s doing
What is a “model”?
a model made of objects representing the document (html)
Which “document” is being referred to in the phrase Document Object Model?
the document in the browser, an html document
What is the word “object” referring to in the phrase Document Object Model?
*all objects that make the model
What is a DOM Tree?
a model of a web page in form of a tree
Give two examples of document methods that retrieve a single element from the DOM.
getElementById( ) - uses value of id attribute
querySelector( ) - this uses css selector or element name etc, returns first matching element
Give one example of a document method that retrieves multiple elements from the DOM at once.
getElementByClassName( )
querySelectorALL( )
Why might you want to assign the return value of a DOM query to a variable?
In situations where you want to use it more than once.
storing it will make performance better later so the query doent’ have to be run again
What console method allows you to inspect the properties of a DOM element object?
console.dir( )
*is dir directory?
Why would a
tag need to be placed at the bottom of the HTML content instead of at the top?
Because JavaScript runs from top to bottom … the html needs to be parsed before we get to our js
What does document.querySelector() take as its argument and what does it return?
takes a css selector , or others, as an argument. it returns the first element
What does document.querySelectorAll() take as its argument and what does it return?
elements (and others) and returns all nodes with that name
what is the defer keyword?
it is legacy style, but it allows for full page to load before creating dom tree, NO MATTER WHERE the script tag is located
What is the purpose of events and event handling?
To run code under specific circumstances
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?
add event listener method
E g,
Document. queryselector(class).addeventlistener(‘click’, callbackfunction)
What is a callback function?
function passed into another as an argument
What object is passed into an event listener callback when the event fires?
the “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 specific html element that was interacted with
I guess you could console log it or you could console.dir it
What is the difference between these two snippets of code?
snipped A
element.addEventListener(‘click’, handleClick)
Snipped B
element.addEventListener(‘click’, handleClick())
the second one will be unfefined
*(review this for as to why)
What is the className property of element objects?
it allows you to get or update a class name
How do you update the CSS class attribute of an element using JavaScript?
select element with class name and assign
- Query selector for getting
- .className = ‘class’
I think without the period for the class name
What is the textContent property of element objects?
allows u to access text content in an element
*And change it?
How do you update the text within an element using JavaScript?
uses textContent property to update it
Is the event parameter of an event listener callback always useful?
I believe it is not only useful but also always necessary
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 because we would have to write some of the code more than once, that is each time we would want to use the code that we could otherwise put inside a variable
Why is storing information about a program in variables better than only storing it in the DOM?
it’s faster to retrieve, and we don’t want to depend on the dom as it’s dynamic and changing
this (below) is a getter/setter. how do u convert from one to the other?
className
(this sets it)
$hotButton.className = ‘hot-button hot’;
vs
(this gets it)
$hotButton.className;
should u use “innterText” method?
no, it’s a hacking vulnerability
Css.
What does the transform property do?
lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual formatting model.
Give four examples of CSS transform functions.
rotate, scale, skew, or translate
what does the space before colon do?:
.pokeball-wrapper:first-child
.pokeball-wrapper :first-child
without space: first child among pokeball wrapper children, that is this Pokeball rappers siblings
with space: first child inside the pokeball wrapper, that is this Pokeball rapper’s children
*double check to confirm this
how do you select items for manipulation with the dom?
Query selector method
how do you listen for things on the dom?
Add event listener
The transition property is shorthand for which four CSS properties?
delay, duration, easing, delay
do you apply transitions to the class or pseudo class?
apply it to the class for full functionality