# SubTextPart Object

> A SubTextPart object represents a user-defined part of a document. A document consists of the main text, and additionally other pieces of text such as text frames and headers or footers, called textparts. A programmer can define further parts called subtextparts to perform operations on smaller pieces of text. Each of the main textparts has a SubTextPartCollection which can be used to add and remove subtextparts or to save the subtextpart's text.

- **Product:** DS Server
- **Section:** Reference
- **Kind:** Object
- **Introduced:** 25.0
- **Path:** DS Server > Reference > JavaScript API > SubTextPart Object
- **1401 words**
- **Web URL:** https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/
- **LLMs URL:** https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/llms-full.txt

---

### Description

A SubTextPart object represents a user-defined part of a document. A document consists of the main text, and additionally other pieces of text such as text frames and headers or footers, called textparts. A programmer can define further parts called subtextparts to perform operations on smaller pieces of text. Each of the main textparts has a SubTextPartCollection which can be used to add and remove subtextparts or to save the subtextpart's text.

### Syntax

```javascript
SubTextPart
```

### Examples

The following example demonstrates `SubTextPart` in a practical document-editing workflow. A SubTextPart object represents a user-defined part of a document. A document consists of the main text, and additionally other pieces of text such as text frames and headers or footers, called textparts. A programmer can define further parts called subtextparts to perform operations on smaller pieces of text. Each of the main textparts has a SubTextPartCollection which can be used to add and remove subtextparts or to save the subtextpart's text.

```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.getItem(function(subTextPart) {
        if (!subTextPart) {
            console.warn("No sub text part is available at the current input position.");
            return;
        }
    
        subTextPart.getID(
            function(result) {
                console.log("get id result:", result);
            },
            onTxError
        );
    }, onTxError);
}, onTxError);
```

---

## In This Section

- [Javascript: SubTextPart.getChildren Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/getchildren-method/llms-full.txt): Returns an array of the children of this SubTextPart.
- [Javascript: SubTextPart.getData Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/getdata-method/llms-full.txt): Gets additional data of the subtextpart.
- [Javascript: SubTextPart.getHighlightColor Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/gethighlightcolor-method/llms-full.txt): Gets the highlight color for the subtextpart.
- [Javascript: SubTextPart.getHighlightMode Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/gethighlightmode-method/llms-full.txt): Gets a value indicating when the subtextpart is highlighted.
- [Javascript: SubTextPart.getID Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/getid-method/llms-full.txt): Gets an identifier for a subtextpart.
- [Javascript: SubTextPart.getLength Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/getlength-method/llms-full.txt): Gets the number of characters in a subtextpart.
- [Javascript: SubTextPart.getName Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/getname-method/llms-full.txt): Relates a user-defined name to a subtextpart.
- [Javascript: SubTextPart.getNestedLevel Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/getnestedlevel-method/llms-full.txt): Gets the subtextpart's nested level.
- [Javascript: SubTextPart.getNumber Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/getnumber-method/llms-full.txt): Gets the subtextpart's number. The first subtextpart has the number 1. The number is defined through the textflow. A textpart with a smaller start position has a smaller number. When an outer subtextpart has the same start position than one of its nested textparts the outer textpart has a smaller number.
- [Javascript: SubTextPart.getOuterMostSubTextPart Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/getoutermostsubtextpart-method/llms-full.txt): Gets a subtextpart's outermost subtextpart.
- [Javascript: SubTextPart.getOuterSubTextPart Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/getoutersubtextpart-method/llms-full.txt): Gets a subtextpart's outer subtextpart.
- [Javascript: SubTextPart.getStart Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/getstart-method/llms-full.txt): Gets the first character position (one-based) of a subtextpart.
- [Javascript: SubTextPart.getText Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/gettext-method/llms-full.txt): Gets the subtextpart's text.
- [Javascript: SubTextPart.getTextFields Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/gettextfields-method/llms-full.txt): Returns an array of static text field information objects.
- [Javascript: SubTextPart.save Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/save-method/llms-full.txt): Saves the subtextpart in a certain format and sends the result back asynchronously by calling a given callback function.
- [Javascript: SubTextPart.scrollTo Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/scrollto-method/llms-full.txt): Sets the current input position to the beginning of a subtextpart and scrolls it into the visible part of the document.
- [Javascript: SubTextPart.setData Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/setdata-method/llms-full.txt): Sets additional data of the subtextpart.
- [Javascript: SubTextPart.setHighlightColor Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/sethighlightcolor-method/llms-full.txt): Sets the highlight color for the subtextpart.
- [Javascript: SubTextPart.setHighlightMode Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/sethighlightmode-method/llms-full.txt): Sets a value indicating when the subtextpart is highlighted.
- [Javascript: SubTextPart.setID Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/setid-method/llms-full.txt): Sets an identifier for the subtextpart.
- [Javascript: SubTextPart.setName Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/setname-method/llms-full.txt): Sets the name of a subtextpart.

---

## Nearby

- **Previous:** [Javascript: StatusBarViewGeneratorColors.setSeparatorColorLight Method](https://docs.textcontrol.com/ds-server/reference/javascript/statusbarviewgeneratorcolors/setseparatorcolorlight-method/llms-full.txt)
- **Next:** [Javascript: SubTextPart.getChildren Method](https://docs.textcontrol.com/ds-server/reference/javascript/subtextpart/getchildren-method/llms-full.txt)
