# DocumentTargetCollection Object

> The DocumentTargetCollection contains a collection of targets.

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

---

### Description

The DocumentTargetCollection contains a collection of [targets](https://docs.textcontrol.com/ds-server/reference/javascript/documenttarget/llms-full.txt).

### Syntax

```javascript
DocumentTargetCollection
```

### Examples

The following example demonstrates `DocumentTargetCollection` in a practical document-editing workflow. The DocumentTargetCollection contains a collection of targets.

```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.getCanAdd(
        function(result) {
            if (result) {
                console.log("get can add is available.");
            } else {
                console.warn("get can add is not available in the current document state.");
            }
        },
        onTxError
    );
}, onTxError);
```

---

## In This Section

- [Javascript: DocumentTargetCollection.add Method](https://docs.textcontrol.com/ds-server/reference/javascript/documenttargetcollection/add-method/llms-full.txt): Adds a new document target to the collection.
- [Javascript: DocumentTargetCollection.clear Method](https://docs.textcontrol.com/ds-server/reference/javascript/documenttargetcollection/clear-method/llms-full.txt): Removes all document targets from the collection.
- [Javascript: DocumentTargetCollection.getCanAdd Method](https://docs.textcontrol.com/ds-server/reference/javascript/documenttargetcollection/getcanadd-method/llms-full.txt): Gets a value indicating whether a new document target can be inserted at the current input position.
- [Javascript: DocumentTargetCollection.getItem Method](https://docs.textcontrol.com/ds-server/reference/javascript/documenttargetcollection/getitem-method/llms-full.txt): Gets the document target at the current text input position or the document target with the specified id.
- [Javascript: DocumentTargetCollection.remove Method](https://docs.textcontrol.com/ds-server/reference/javascript/documenttargetcollection/remove-method/llms-full.txt): Removes the target from the collection.

---

## Nearby

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