Chapter 5: Document Object Model Flashcards
What programming concept is the DOM an example of?
An API (Application Programming Interface)
What type of Nodes exist in the DOM?
document
element
Attribute
text
Each node is not an object. True or false?
False. Each node is an object with its own properties and methods
What methods can select an individual element node
getElementById()
querySelector()
What methods select multiple elements (novelist)?
getElemenetsByClassName()
getElementsByTagName()
querySelectorAll()
What methods allow you to traverse the DOM?
parentNode
previousSibling / nextSibling
firstChild lastChild
What methods allow you to access/update text nodes?
nodeValue
What methods allow you to work with HTML content?
innerHTML textContent createElement() createTextNode(); appendChild(); removeChild();
What methods or properties allow you to access to update attribute nodes?
className / id
hasAttribute();
getAttribute();
setAttribute();
removeAttribute();
What do the following terms mean?
DOM query
caching the selection
stores a reference
DOM query is a method to find elemtns in the dom
caching refers to assigning result of a dom query to variable. Saves resources if we need ro keep working with an element
Reference means that it stores the location of the node (not the actual node)
What is a Nodelist
A query that returns a collection of Nodes (at least 1. so if it only finds 1 match its still stored in a Nodelist, that’s different from get ing an individual element).
To access an element in a list we use a Array syntax (either [] or item();
What determines if a Nodelist is static or live?
It depends on the DOM query method
a live novelist is always run fresh and grabs matching elements. These are methods beginning getElementsBy…
A statici nodelist is run once and does not update subsequent times (so won’t pick up changes in the DOm). querySelector methods create static lists
Why’s it a good idea to check a novelist has at least 1 results before running the code?
It wastes resources otherwise nothing to update
if()elements.length >= 1 { //do these cool changes }
Why is Array syntax preferred over item method
It’s faster
What’s the DOM method to select elements by className?
getElementsByClassName(‘className’)
e.g. getElementsByClassName(‘hot’)
This method returns a Nodelist
It’s a newer DOM method so some browsers (IE8 -) don’t support it
What’s the DOM method to select elements by their tag?
getElementsByTagName(‘tagName’)
e.g. getElementsByTagName(‘a’)