Skip to content

5.18.19

Compare
Choose a tag to compare
@xiaoiver xiaoiver released this 01 Nov 03:10
· 67 commits to next since this release
3a65536

Patch Changes

Online DEMO

The insertBefore() method inserts a node before a reference node as a child of a specified parent node.

const group1 = new Element();
const group2 = new Element();
const group3 = new Element();
const group4 = new Element();

// 2, 4, 3
group1.append(group2, group3);
group1.insertBefore(group4, group3);

If the given node already exists in the document, insertBefore() moves it from its current position to the new position. That is, it will automatically be removed from its existing parent before appending it to the specified new parent.

// 2, 3, 4 -> 2, 4, 3
group1.append(group2, group3, group4);
group1.insertBefore(group4, group3);

If refNode is null, then newNode is inserted at the end of node's child nodes.

// 2, 3, 4
group1.append(group2, group3);
group1.insertBefore(group4, null);

If refNode is not the child of parentNode, then newNode is inserted at the end of node's child nodes.

// 2, 3, 4
group1.append(group2, group3);
group1.insertBefore(group4, group5); // non-existed node