Inserting an element from the end of a body is appendChild, so what is used before inserting it into the first element?

inserting an element from the end of a body is appendChild, so what is used before inserting it into the first element?

Apr.10,2022

let div = document.createElement('div')
let firstChild = document.body.firstChild
document.body.insertBefore(div, firstChild)

is summarized as a function:

function insertBefore(node, newElement) {
  node.insertBefore(newElement, node.firstChild)
}

let div = document.createElement('div')
insertBefore(document.body, div)

insertbefore


rootNode.insertAdjacentHTML ('afterbegin', template); the


insertBefor method adds a new node (relative to the child node) in front of the existing node. For example: insertBefore (newchild,rechild)

Menu