DOM: More Methods Flashcards
(20 cards)
parentElement
Returns the DOM node parent element, or null if it has no parent or is not a DOM element
element.children
Returns a live HTMLCollection which contains all the child elements of the specified element
element.firstElementChild
Returns the first element within the specified element
element.previousElementSibling
Returns the element immediately preceding the specified one in the parent’s children list
element.nextElementSibling
Returns the element immediately following the specified one in the parent’s children list
element.nextElementSibling
Returns the element immediately following the specified one in the parent’s children list
element.childNode
Returns a live NodeList of child nodes of the given element where the first child node is assigned index 0. Child nodes include elements, texts, and comments.
element.firstChild
Returns the node’s first child in the tree, or null if the node has no children
element.firstChild.nodeValue
Returns the node’s value
In this example, it returns the node value of first child node on the specified element
element.previousSibling
Returns the node immediately preceding the specified one in the parent’s childNodes list, or null if the specified node is the first in the list
element.nextSibling
Returns the node immediately following the specified one in the parent’s childNodes list, or null if the node is the last in that list
document.createElement
Creates an element on the document
document.createTextNode
Creates a text node. Can be used to escape HTML character
element.appendChild( child) // no quotes
Adds a child node to the DOM
element.removeChild( child) // no quotes
Removes the child node from the DOM and returns the removed node
getAttribute
Returns the value of a specified attribute on the elements
setAttribute
Sets the value of a specified attribute on the element
element.classList
Returns a live DOMTokenList of class attributes of the specified element
element.classList.add()
Adds the given tokens to the list omitting any that are already present
element.classList.remove()
Removes the given tokens to the list