# Javascript: DocumentLink.setDocumentTarget Method

> Sets an object of the type DocumentTarget specifying to where the link points.

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

---

### Description

Sets an object of the type DocumentTarget specifying to where the link points.

### Syntax

```javascript
<void> DocumentLink.setDocumentTarget(<DocumentTarget> documentTarget, [<EmptyRequestCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| documentTarget | Specifies to where the link points. |
| callback | Optional. Is called when the operation completed. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `DocumentLink.setDocumentTarget` in a practical document-editing workflow. It sets an object of the type DocumentTarget specifying to where the link points.

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

function configureDocumentTarget(documentTarget) {
    TXTextControl.textParts.getMainText(function(mainText) {
        const documentLinks = mainText.documentLinks;
        documentLinks.getItem(function(documentLink) {
            if (!documentLink) {
                console.warn("No document link is available at the current input position.");
                return;
            }
        
            documentLink.setDocumentTarget(
                documentTarget,
                function() {
                    console.log("set document target completed.");
                },
                onTxError
            );
        }, onTxError);
    }, onTxError);
}
```

---

## Nearby

- **Previous:** [Javascript: DocumentLink.setDescriptiveText Method](https://docs.textcontrol.com/ds-server/reference/javascript/documentlink/setdescriptivetext-method/llms-full.txt)
- **Next:** [DocumentLinkCallback Function](https://docs.textcontrol.com/ds-server/reference/javascript/documentlinkcallback/llms-full.txt)
