> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# `__InsertElementBefore`

## Introduction

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

## Syntax

```jsx
__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.

```jsx
// 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);
```
