# Javascript: DocumentTargetCollection.clear Method

> Removes all document targets from the collection.

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

---

### Description

Removes all document targets from the collection.

### Syntax

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

### Parameters

| Parameter | Description |
|---|---|
| callback | Optional. Is called when the operation completed. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

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

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

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

---

## Nearby

- **Previous:** [Javascript: DocumentTargetCollection.add Method](https://docs.textcontrol.com/ds-server/reference/javascript/documenttargetcollection/add-method/llms-full.txt)
- **Next:** [Javascript: DocumentTargetCollection.getCanAdd Method](https://docs.textcontrol.com/ds-server/reference/javascript/documenttargetcollection/getcanadd-method/llms-full.txt)
