# Javascript: CommentCollection.addAtPosition Method

> Creates a comment with the specified comment string, start position and length.

- **Product:** DS Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 30.0
- **Path:** DS Server > Reference > JavaScript API > Javascript: CommentCollection.addAtPosition Method
- **524 words**
- **Web URL:** https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/addatposition-method/
- **LLMs URL:** https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/addatposition-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/addatposition-method/llms-full.txt

---

### Description

Creates a comment with the specified comment string, start position and length.

### Syntax

```javascript
<void> CommentCollection.addAtPosition(<string> comment, <number> start, <number> length, [<AddCommentCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| comment | The comment string. |
| start | The index (one-based) of the first character which belongs to the comment. |
| length | The number of characters which belong to the comment. |
| callback | Optional. Receives the result of the add operation. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `CommentCollection.addAtPosition` in a practical document-editing workflow. It creates a comment with the specified comment string, start position and length.

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

TXTextControl.textParts.getMainText(function(mainText) {
    const comments = mainText.comments;
    comments.addAtPosition(
        "Please review this section.",
        1,
        5,
        function(response) {
            if (!response) {
                console.warn("No comment callback data was returned.");
                return;
            }
            
            console.log("add at position result:", response);
        },
        onTxError
    );
}, onTxError);
```

---

## Nearby

- **Previous:** [Javascript: CommentCollection.add Method](https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/add-method/llms-full.txt)
- **Next:** [Javascript: CommentCollection.addReply Method](https://docs.textcontrol.com/ds-server/reference/javascript/commentcollection/addreply-method/llms-full.txt)
