# Javascript: CommentCollection.add Method

> Creates a comment with the specified comment string. The current text selection defines the commented text.

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

---

### Description

Creates a comment with the specified comment string. The current text selection defines the commented text.

### Syntax

```javascript
<void> CommentCollection.add(<string> comment, [<AddCommentCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| comment | The comment string or null. Use null to open a text input box so that the end-user can type the comment's text for the currently selected text. The new comment is inserted after the text input box has been closed. |
| 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.add` in a practical document-editing workflow. It creates a comment with the specified comment string. The current text selection defines the commented text.

```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.add(
        "Please review this section.",
        function(response) {
            if (!response) {
                console.warn("No comment callback data was returned.");
                return;
            }
            
            console.log("add result:", response);
        },
        onTxError
    );
}, onTxError);
```

---

## Nearby

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