Skip to content

Function: insertAfter() ​

ts
function insertAfter<T>(newNode, referenceNode): T;

Inserts a node after a reference node.

Type Parameters ​

Type Parameter
T extends Node

Parameters ​

ParameterTypeDescription
newNodeTThe node to insert.
referenceNodeNodeThe reference node.

Returns ​

T

The inserted node.

Example ​

ts
const parent = document.createElement('div')
const a = document.createElement('span')
const b = document.createElement('span')
parent.appendChild(a)
insertAfter(b, a)
parent.children.length // => 2

Since ​

1.0.0

Released under the MIT License.