DOM Flashcards
Why do we log things to the console?
Debugging and anytime we want to know the value a variable holds
What is a “model”?
Any representation of something
Which “document” is being referred to in the phrase Document Object Model?
XML or HTML document that is currently loaded (and all of its info)
What is the word “object referring to in the phrase Document Object Model?
The web page loaded in the current window or tab
What is the DOM tree?
A tree of all of the elements with the document node at its root.
Give two examples of document methods that retrieve a single element from the DOM.
Document.querySelector() & Document.getElementById()
Between Document.querySelector() & Document.getElementById() — which is faster? & why
getElementById b/c it doesn’t have to search
Give one example of a document method that retrieves multiple elements from the DOM.
Document.querySelectorAll (and Document.getElementsbyClass())
What is the difference between querySelectorAll() and getElementsByClass() ?
QuerySelectorAll = nodelist ; getElementsbyClass = HTML collection
Why might you want to assign the return value of a DOM query to a variable?
So you can call and manipulate it later
What console method allows you to inspect the properties of a DOM element object?
The .dir method
Why would a tag need to be placed at the bottom of the HTML document?
You can’t query HTML that isn’t loaded yet
What does document.querySelector() take as its argument and what does it return?
It takes a string with a selector and returns the element that matches that string —> else null
What does querySelectorAll() take as its argument and what does it return?
Takes a selector as a string as argument, returns a nodelist of all elements that match that selector.
What is the purpose of events and event handling?
Create and manage interactivity with the webpage!
Are all possible parameters required to use a JavaScript method or function?
Noooo — only the required ones (sometimes none)
What method of element objects lets you set up a function to be called when a specific type of event occurs?
Document.addEventListener()