# Javascript: DocumentTargetCollection.getItem Method

> Gets the document target at the current text input position or the document target with the specified id.

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

---

### Description

Gets the document target at the current text input position or the document target with the specified id.

### Syntax

```javascript
<void> DocumentTargetCollection.getItem(<RequestDocumentTargetCallback> callback, [<ErrorCallback> errorCallback], [<number> nameOrId])
```

### Parameters

| Parameter | Description |
|---|---|
| callback | The callback function that receives the requested value. |
| errorCallback | Optional. Is called when the operation failed with an error. |
| nameOrId | Optional. Specifies either the document target's identifier set with the ID property or the document target's target name set with the TargetName property. The method returns null if a target with the specified identifier or name does not exist. |

### Examples

The following example demonstrates `DocumentTargetCollection.getItem` in a practical document-editing workflow. It gets the document target at the current text input position or the document target with the specified id.

```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.getItem(
        function(result) {
            if (!result) {
                console.warn("No document target was returned.");
                return;
            }
            
            console.log("get item result:", result);
        },
        onTxError,
        25
    );
}, onTxError);
```

---

## Nearby

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