dom querying Flashcards
Why do we log things to the console?
to track and debug our code, check results along the way
What is a “model”?
representation
Which “document” is being referred to in the phrase Document Object Model?
the current webpage
What is the word “object” referring to in the phrase Document Object Model?
a JavaScript object
What is a DOM Tree?
model of a web page made of objects
Give two examples of document methods that retrieve a single element from the DOM.
getElementById(‘id’)
querySelector(‘selector’) (uses a CSS selector, returns first matching element)
Give one example of a document method that retrieves multiple elements from the DOM at once.
getElementsByClassName(‘class’)
getElementsByTagName(‘tag’)
querySelectorAll(‘selector’) (uses CSS selector, returns all matching elements)
Why might you want to assign the return value of a DOM query to a variable?
when you need to work with an element more than once
What console method allows you to inspect the properties of a DOM element object?
console.dir
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
html loads top to bottom, the script needs to run after the page has loaded
What does document.querySelector() take as its argument and what does it return?
takes selector (like css selector) and returns a dom element
What does document.querySelectorAll() take as its argument and what does it return?
takes selector (like css selector) and returns a NodeList of dom element(s)