dom-querying Flashcards
Why do we log things to the console?
to make sure out code is working and doing what we want it to do. sort of like a progress update for testing and tracking
What is a “model”?
a respresentation of a structure, in this case its a representation of the html structure aka the DOM tree
Which “document” is being referred to in the phrase Document Object Model?
the HTML doc
What is the word “object” referring to in the phrase Document Object Model?
the objects in this case are the html element representations that make up the DOM tree
a javascript representation of an html structure within a browser
What is a DOM Tree?
the way a browser structures its representation of an html structure
an element plus all of its content and configuration.
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.
getElementsByClass();
querySelectorAll();
Why might you want to assign the return value of a DOM query to a variable?
in the event that you need to call on it more than once so that you aren’t wasting effort
so it doesn’t have to search the dom tree every time you need it
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?
because the HTML would need to finish loading before the JavaScript if you are planning to access the html from a JavaScript file
What does document.querySelector() take as its argument and what does it return?
it takes a css selector and returns the first matching element
What does document.querySelectorAll() take as its argument and what does it return?
it takes a css selector and returns a node list containing all matching elements
nodelists are not arrays or elements, its a js object created to hold a list of dom elements. its just data that you can iterate through