DOM QUERYING Flashcards
Why do we log things to the console?
The console is a panel that displays important messages, like errors, for developers. Much of the work the computer does with our code is invisible to us by default. If we want to see things appear on our screen, we can print, or log , to our console directly.
What is a “model”?
When the browser loads a webpage it recreates a model in memory
Which “document” is being referred to in the phrase Document Object Model?
HTML document The current web page
What is the word “object” referring to in the phrase Document Object Model?
The objects are the elements, attributes, text that make up the html web page
What is a DOM Tree?
When a browser loads a web page it creates a model of that page.
The model is called a DOM Tree and is stored in browser’s memory.
Consisiting of 4 types of nodes:
document
element
attribute
text
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.
getElementsByClassName( )
Why might you want to assign the return value of a DOM query to a variable?
It saves the browser looking throught the dom tree to find the same element again
What console method allows you to inspect the properties of a DOM element object?
console.dir( )
dir = directory
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
So that the html content loads first
The browser needs to parse all of the elements in the HTML page before the JavaScript code can access them.
What does document.querySelector() take as its argument and what does it return?
It can take CSS selectors and returns the first matching element
What does document.querySelectorAll() take as its argument and what does it return?
Takes in CSS selectors and returns all matching elements