add and remove children to element in js

Table of Contents

parent.appendChild(child) // tail
parent.insertBefore(child,oldChild) // insert before oldChild; oldChild is reference to an existing element
parent.insertBefore(child,null) // tail
parent.insertBefore(child,oldChild.nextElementSibling) //insert aftrer oldChild
parent.insertBefore(child,firstChild) //head
parent.replaceChild(child,oldChild) // replace oldChild with child
parent.removeChild(oldChild) // remove oldChild from parent's children

Backlinks

Author: Linfeng He

Created: 2024-04-03 Wed 23:16