Document Object Model (DOM) Flashcards
Why do we log things to the console?
To know what our code is doing at a given time
What is a “model”?
It’s a representation of something else or a guideline or a blueprint
Which “document” is being referred to in the phrase Document Object Model?
HTML file
What is the word “object” referring to in the phrase Document Object Model?
The model is made up of object data types (ie. windows object, document object, element objects)
What is a DOM Tree?
It is an element plus all of its elements.
Give two examples of document methods that retrieve a single element from the DOM.
.getElementById()
.querySelector()
Why might you want to assign the return value of a DOM query to a variable?
It saves the browser looking through the DOM tree to find the same elements again. It’s caching the selection. It is storing the location of the node.
Why might you want to assign the return value of a DOM query to a variable?
It saves the browser looking through the DOM tree to find the same elements again. It’s caching the selection. It is storing the location of the node. It also allows you to edit it afterward.
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
In order to parse through all of the information on the webpage so it can access them
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
In order to parse through all the HTML information on the webpage so the DOM can access it.
What does document.querySelector() take as its argument and what does it return?
takes on a selector and returns an element.
What does document.querySelectorAll() take as its argument and what does it return?
all selectors and returns ever static NodeList-(list of nodes)
What can DOM do?
change all the HTML elements in the page,
change all the HTML attributes in the page,
remove existing HTML elements and attributes,
add new HTML elements and attributes,
JavaScript can react to all existing HTML events in the page,
JavaScript can create new HTML events in the page.
getElementById()
Uses the value of an elements id attribute (which should be unique within the page).
querySelector()
Uses a CSS selector and returns the first matching element.
getElementsByClassName()
selects all elements that have a specific value for their class attribute.
getElementsByTagName()
Selects all elements that have the specified tag name.
querySelectorAll()
Uses a CSS selector to select all matching elements
parentNode
Selects the parent of the current element node
previousSibling/nextSibling
Selects the previous or next sibling from the DOM tree
firstChild/ lastChild
Select the first or last child of the current element.
$
Indicator that this holds a dom element