JS DOM: Insert, Remove, Replace Element
Insert as sibling or child
-
node.insertAdjacentElement(position, newNode) -
insert a new node as previous/next sibling, or as first/last child.
Insert as child
Append as last child
parent.appendChild(newNode)
Insert before a specific child
parent.insertBefore(newNode, nodeX)-
Inserts newNode as a new child of parent before nodeX.
Remove Child
-
parent.removeChild(oldNode)
Replace Child
-
parent.replaceChild(newNode, oldNode) -
Replaces the child node oldNode of parent with newNode.
If newNode is in the same doc, move it to the new place.
Remove all children
Replace all children by text
Basic DOM Element Methods
- JS DOM: Node, Node Type, Element
- JS DOM: Get Element by ID, Name, Class etc
- JS DOM: Get Current Script Element
- JS DOM: Get Element Parent, Child, Sibling
- JS DOM: NodeList vs HTMLCollection
- JS DOM: Iterate HTMLCollection
- JS DOM: Element Attribute Methods
- JS DOM: Class Attribute (get add remove toggle)
- JS DOM: Create Element, Clone
- JS DOM: Insert, Remove, Replace Element
- JS DOM: insert Adjacent Element
- JS DOM: appendChild
- JS DOM: textContent, innerHTML, innerText, nodeValue
- JS DOM: Remove Element
- JS DOM: Remove All Children
- JS DOM: Change Element Content
- JS DOM: Add, Remove Event Handler