# Javascript: SubTextPartCollection.add Method

> Adds a new SubTextPart to the collection.

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

---

### Description

Adds a new SubTextPart to the collection.

### Syntax

```javascript
<void> SubTextPartCollection.add(<String> name, <Number> id, <Number> start, <Number> length, [<AddSubTextPartCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| name | Specifies the name of the subtextpart. This parameter can be null or an empty string to indicate, that the subtextpart has no name. |
| id | Specifies an identifier for the subtextpart. This parameter can be 0 to indicate, that the subtextpart has no identifier. |
| start | Specifies the index (one-based) of the first character which belongs to the subtextpart. |
| length | Specifies the number of characters which belong to the subtextpart. |
| callback | Optional. Receives information about the result of the adding and the added subtextpart. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `SubTextPartCollection.add` in a practical document-editing workflow. It adds a new SubTextPart to the collection.

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

TXTextControl.textParts.getMainText(function(mainText) {
    const subTextParts = mainText.subTextParts;
    subTextParts.add(
        "InvoiceAddress",
        25,
        1,
        5,
        function(response, addResult) {
            if (!response) {
                console.warn("No sub text part callback data was returned.");
                return;
            }
            
            console.log("add result:", response);
        },
        onTxError
    );
}, onTxError);
```

---

## Nearby

- **Previous:** [SubTextPartCollection Object](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpartcollection/llms-full.txt)
- **Next:** [Javascript: SubTextPartCollection.AddResult Enumeration](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpartcollection/addresult-enumeration/llms-full.txt)
