DOM Flashcards
Why do we log things to the console?
to see what our code is doing
What is a “model”?
a representation of something else
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?
referring to the JavaScript objects that the DOM reads the document as
What is a DOM Tree?
all the nodes of an element; a model of a web page the browser stores in memory (DOM element plus all the children inside it)
Give two examples of document methods that retrieve a single element from the DOM.
getElementById( )
querySelector( )
Give one example of a document method that retrieves multiple elements from the DOM at once.
getElementByClassName( )
getElementByTagName( )
querySelectorAll( )
Why might you want to assign the return value of a DOM query to a variable?
if you want to work with that element node more than once
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?
the browser needs to parse all the elements of the HTML page before the JavaScript code can access them
What does document.querySelector() take as its argument and what does it return?
argument: a string containing a CSS selector describing the element you want to work with
return: ONE HTMLElement object representing the first element in the document that matches the selector
What does document.querySelectorAll() take as its argument and what does it return?
argument: DOMString containing one or more selectors
return: a NodeList containing one Element object for each element that matches at least one of the specified selectors, otherwise an empty NodeList if none match
Why do we log things to the console?
to see how our code is working
What is the purpose of events and event handling?
allows your page to be interactive
What do [ ] square brackets mean in function and method syntax documentation?
it means it is optional to include