# Javascript: SubTextPartCollection.remove Method

> Removes a subtextpart from the collection including all its nested subtextparts.

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: SubTextPartCollection.remove Method
- **590 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/subtextpartcollection/remove-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/subtextpartcollection/remove-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/subtextpartcollection/remove-method/llms-full.txt

---

### Description

Removes a subtextpart from the collection including all its nested subtextparts.

### Syntax

```javascript
<void> SubTextPartCollection.remove(<SubTextPart> subTextPart, <Boolean> keepText, <Boolean> keepNested, [<RequestBooleanCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| subTextPart | Specifies the subtextpart to remove. |
| keepText | If this parameter is set to true, the subtextpart is removed without deleting its visible text. Otherwise, the visible text is also removed. |
| keepNested | If this parameter is set to true, nested subtextparts are preserved. When the keepText parameter is set to false, this parameter is ignored. |
| callback | Optional. Receives a value which indicates whether the remove was succesful. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `SubTextPartCollection.remove` in a practical document-editing workflow. It removes a subtextpart from the collection including all its nested subtextparts.

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

function remove(subTextPart) {
    TXTextControl.textParts.getMainText(function(mainText) {
        const subTextParts = mainText.subTextParts;
        subTextParts.remove(
            subTextPart,
            true,
            true,
            function(result) {
                if (result) {
                    console.log("remove is available.");
                } else {
                    console.warn("remove is not available in the current document state.");
                }
            },
            onTxError
        );
    }, onTxError);
}
```

---

## Nearby

- **Previous:** [Javascript: SubTextPartCollection.getItem Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/subtextpartcollection/getitem-method/llms-full.txt)
- **Next:** [SubTextPartEventArgs Object](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/subtextparteventargs/llms-full.txt)
