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