__InsertElementBefore

Introduction

Inserts an Element node into the specified parent node, before the reference node.

Syntax

__InsertElementBefore(parent: Element, child: Element, referenceNode: Element) : Element;

Parameters

Key Description
parent The parent node object.
child The child node to be inserted into the parent node.
referenceNode The reference node before which the child node needs to be inserted. If the reference node is null, the child node will be inserted at the end.

Return Value

Returns the inserted child node.

Example

The frontend framework can perform the insertion operation as follows.

// main-thread.js
let first = __CreateElement('view', 0, {});

let last = __CreateElement('view', 0, {});

let mid = __CreateElement('view', 0, {});

let parent = __CreateElement('view', 0, {});

__AppendElement(parent, first);
__AppendElement(parent, last);

__InsertElementBefore(parent, mid, last);
Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.