dom-querying Flashcards
Why do we log things to the console?
debugging, confirming values or outcomes from code, communicating with other devs working on the project
What is a “model”?
a model is a representation of a structured document in a tree-like structure. The model consists of a set of objects that represent the various elements in the document.
Which “document” is being referred to in the phrase Document Object Model?
when we refer to the “document” in the phrase “Document Object Model,” we are talking about a structured document that is displayed in a web browser.
What is the word “object” referring to in the phrase Document Object Model?
“object” refers to a data structure that represents an element in a structured document.
What is a DOM Tree?
a tree-like structure that represents the structure of a structured document. The tree consists of a set of objects that represent the various elements in the document.
Give two examples of document methods that retrieve a single element from the DOM.
getElementById(): This method retrieves an element from the DOM based on its unique id attribute.
querySelector(): This method retrieves an element from the DOM based on a CSS selector.
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll(). This method retrieves a collection of elements from the DOM based on a CSS selector.
Why might you want to assign the return value of a DOM query to a variable?
reusability - without having to query the DOM ( more efficient )
Readability - gives the element a descriptive name
Modification - easier to modify becasue you can access using the descriptive variable name.
What console method allows you to inspect the properties of a DOM element object?
console.dir - it will display an interactive list of the properties and methods of the element
Why would a
tag need to be placed at the bottom of the HTML content instead of at the top?
To increase performance of the page loading. Since Scripts are run before rendering HTML it might be better to put a longer loading script tag at the end so the HTML loads quicker. Also in DOM querying 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?
the argument it takes in a string containing a CSS selector and it returns the first element that matches.
What does document.querySelectorAll() take as its argument and what does it return?
It takes a string containing a CSS selector and returns all elements that match….a node list