Skip to content

Node.insertAfter method

Node › insertAfter

Official

Inserts a child node after the current node.

Signature:

insertAfter(node: T, child: Node | null): T

Parameters:

Parameter Type Description
node T The node to insert.
child Node | null The child node to insert after.

Returns: TThe inserted node.

Example:

const parent = createEl('p');
const child1 = parent.createEl('strong', { text: '1' });
const child2 = parent.createEl('strong', { text: '2' });
const child3 = parent.createEl('strong', { text: '3' });
const newNode = createEl('em', { text: '4' });
parent.insertAfter(newNode, child2);
console.log(parent); // <p><strong>1</strong><strong>2</strong><em>4</em><strong>3</strong></p>