JS230 Flashcards
Front-end development with JavaScript!
What is the DOM?
The DOM is an in-memory object representation of an HTML document.
What is the purpose of the DOM?
The DOM provides the functionality needed to build modern interactive user experiences.
What is document
?
document
is the top-most DOM node that represents the entire HTML document.
Node.nodeName
Returns the name of the current node as a string.
What does the .nodeName
property for elements return?
Returns the name of the corresponding tag in uppercase. EX: ‘P’ for paragraph.
Node.nodeType
Returns a number that returns a node type constant.
How would you determine if a node was an element node?
Use a comparison expression comparing node.nodeType
to Node.ELEMENT_NODE
.
How would you determine if a node was a text node?
Use a comparison expression comparing the node.nodeType
to Node.TEXT_NODE
.
An element node’s .nodeValue
property returns….
null
Node.nodeValue
Returns the value of a node.
A text node’s .nodeValue
property returns…
The textual content of the node.
What does the .textContent
property return for element nodes?
The .textContent
property returns a string of all the textual content of all the nodes inside the element.
Element
nodes represent…
HTML tags.
The best way to determine a node’s type from the console is…?
node.toString()
which will allow you to read the node’s name.
The best way to determine an Element
node’s type (tag it represents from HTML) in a program is…?
Use the instanceof
operator.
EX: node instance of HTMLParagraphElement
Node.childNodes
Returns a collection of the calling node’s children.
Node.firstChild
Returns the calling node’s first child OR null
.
Node.lastChild
Returns the calling node’s last child OR null
.
Node.parentNode
Returns the calling node’s parent node OR null
if the topmost node.
A live collection…
automatically updates to reflect changes in the DOM.
Node.nextSibling
Returns the node’s next sibling OR null
.
Node.previousSibling
Returns the node’s previous sibling OR null
.
What are HTML attributes?
Elements in HTML have attributes. Attributes are values that configure the elements or adjust their behavior in various ways to meet the criteria that users want.
Node.getAttribute()
Retrieves the value of the node instance’s attribute passed as an argument.