replaceChild

fun <T : Node> replaceChild(node: Node, child: T): T(source)

The replaceChild() method of the Node interface replaces a child node within the given (parent) node.

MDN Reference