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

# BeforePublishEvent: add() method

APISummary
The `add` method can be used to register listening for a certain element event.

## grammar

```ts
add(name: string, listener: () => {}, context?: BaseInstance): BeforePublishEvent;
```

### Parameters

#### name

```ts
name: string;
```

Specify the name of the element event to be listened to.

#### listener

```ts
listener: () => {};
```

Specify the listening callback.

#### context

```ts
context?: BaseInstance
```

Front-end custom `component` or `card` instance.

### return value

`BeforePublishEvent` object.

## Compatibility

**Compatibility Table**

**Query:** `lynx-api.lynx.lynx-before-publish-event.add`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/lynx/lynx-before-publish-event/add.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| add | Yes (2.14) | Yes (3.4) | Yes (2.14) | Yes (3.5) | Yes (3.5) | Yes |

**`add`**

Register to listen for an element event.

