# Javascript: HypertextLinkCollection.add Method

> Inserts a new hypertext link at the current input position.

- **Product:** DS Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** DS Server > Reference > JavaScript API > Javascript: HypertextLinkCollection.add Method
- **489 words**
- **Web URL:** https://docs.textcontrol.com/ds-server/reference/javascript/hypertextlinkcollection/add-method/
- **LLMs URL:** https://docs.textcontrol.com/ds-server/reference/javascript/hypertextlinkcollection/add-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/ds-server/reference/javascript/hypertextlinkcollection/add-method/llms-full.txt

---

### Description

Inserts a new hypertext link at the current input position.

### Syntax

```javascript
<void> HypertextLinkCollection.add(<string> text, <string> target, [<RequestHypertextLinkCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| text | Specifies the visible text of the hypertext link. |
| target | Specifies a string specifying to where the hypertext link points. |
| callback | Optional. Receives the added document link or null if no link could be added. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `HypertextLinkCollection.add` in a practical document-editing workflow. It inserts a new hypertext link at the current input position.

```javascript
function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

TXTextControl.textParts.getMainText(function(mainText) {
    const hypertextLinks = mainText.hypertextLinks;
    hypertextLinks.add(
        "Quarterly report",
        "https://www.example.com/invoices/2026",
        function(result) {
            if (!result) {
                console.warn("No hypertext link was returned.");
                return;
            }
            
            console.log("add result:", result);
        },
        onTxError
    );
}, onTxError);
```

---

## Nearby

- **Previous:** [HypertextLinkCollection Object](https://docs.textcontrol.com/ds-server/reference/javascript/hypertextlinkcollection/llms-full.txt)
- **Next:** [Javascript: HypertextLinkCollection.getItem Method](https://docs.textcontrol.com/ds-server/reference/javascript/hypertextlinkcollection/getitem-method/llms-full.txt)
