# Javascript: DocumentLinkCollection.clear Method

> Removes all document links from 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.clear Method
- **390 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/documentlinkcollection/clear-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/documentlinkcollection/clear-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/documentlinkcollection/clear-method/llms-full.txt

---

### Description

Removes all document links from the collection.

### Syntax

```javascript
<void> DocumentLinkCollection.clear(<boolean> keepText, [<EmptyRequestCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| keepText | If this parameter is set to true, all document links are removed without deleting their texts. Otherwise, the texts are also deleted. |
| callback | Optional. Is called when the operation completed. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `DocumentLinkCollection.clear` in a practical document-editing workflow. It removes all document links from the collection.

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

TXTextControl.textParts.getMainText(function(mainText) {
    const documentLinks = mainText.documentLinks;
    documentLinks.clear(
        true,
        function() {
            console.log("clear completed.");
        },
        onTxError
    );
}, onTxError);
```

---

## Nearby

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