# Javascript: DocumentLinkCollection.add Method

> Adds a new document link to the collection.

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: DocumentLinkCollection.add Method
- **498 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/documentlinkcollection/add-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/documentlinkcollection/add-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/documentlinkcollection/add-method/llms-full.txt

---

### Description

Adds a new document link to the collection.

### Syntax

```javascript
<void> DocumentLinkCollection.add(<string> text, <DocumentTarget> documentTarget, [<RequestDocumentLinkCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| text | Visible text of the link. |
| documentTarget | The link target. |
| 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 `DocumentLinkCollection.add` in a practical document-editing workflow. It adds a new document link to the collection.

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

function add(documentTarget) {
    TXTextControl.textParts.getMainText(function(mainText) {
        const documentLinks = mainText.documentLinks;
        documentLinks.add(
            "Quarterly report",
            documentTarget,
            function(result) {
                if (!result) {
                    console.warn("No document link was returned.");
                    return;
                }
                
                console.log("add result:", result);
            },
            onTxError
        );
    }, onTxError);
}
```

---

## Nearby

- **Previous:** [DocumentLinkCollection Object](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/documentlinkcollection/llms-full.txt)
- **Next:** [Javascript: DocumentLinkCollection.clear Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/documentlinkcollection/clear-method/llms-full.txt)
