DOM manipulation
Navigating the DOM Tree with Node Properties
parentNode and parentElement
parentNode and parentElementconst child = document.getElementById("child");
const parentElement = child.parentNode;const parentElement = element.parentElement;childNodes
childNodesconst childNodes = parent.childNodes;firstElementChild
firstElementChildconst parent = document.getElementById("parent");
const firstChildElement = parent.firstElementChild;lastElementChild
lastElementChildchildren[i]
children[i]nextSibling and previousSibling
nextSibling and previousSiblingquerySelector()
querySelector()querySelectorAll()
querySelectorAll()closest()
closest()Adding Elements
appendChild()
appendChild()insertBefore():
insertBefore():Creating Elements
Modifying Text
textContent
textContentinnerHTML
innerHTMLRemoving Elements
Modifying Attributes
Handling Classes
Modifying Styles
List of References
Last updated