DOM Flashcards
Why do we log things to the console?
to debug things and figure it all out
What is a “model”?
something recreating or ‘modeling’ something else
a tree of the stuff in the html
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?
refers to the data type object in js
What is a DOM Tree?
a model of a webpage
-an element + all its configuration + all its contents, represented as an object in the dom
Give two examples of document methods that retrieve a single element from the DOM.
getelementbyid, queryselector
-the only method you ever need to use to retrieve 1 thing from dom is queryselector
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.queryselectorall
Why might you want to assign the return value of a DOM query to a variable?
store it incase you need to use it more. Otherwise, you’ll have to query something 100x
storing as variables > queryselectoring x 100, because queryselectoring searches the whole page a lot
What console method allows you to inspect the properties of a DOM element object?
document.dir() method
Why would a
tag need to be placed at the bottom of the HTML content instead of at the top?
because you need to scan through the whole page to find stuff
your js would load before your html that it references
if you queryselector something that doesn’t exist, u get null
script at bottom is important
What does document.querySelector() take as its argument and what does it return?
it takes a css selector, it returns the element and its stuff
What does document.querySelectorAll() take as its argument and what does it return?
takes a css selector, returns a nodelist containing all the elements
Nodes? Nodelists?
nodelists -> a collection of nodes. Not arrays, just a collection
Nodes -> The DOM Node interface is an abstract base class upon which many other DOM API objects are based, thus letting those object types to be used similarly and often interchangeably. As an abstract class, there is no such thing as a plain Node object. All objects that implement Node functionality are based on one of its subclasses. Most notable are Document, Element, and DocumentFragment.
What is the purpose of events and event handling?
it makes the page intractable
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(‘eventtypehere’, function)
What is a callback function?
when you pass a function as an argument to another function
yo dawg i heard u like functions
What object is passed into an event listener callback when the event fires?
an object with a bunch of data to describe the event that occured… 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?
its the element where the event originated from.