# Javascript: TXTextControl.selection Property

> Returns the current selection or sets the selection's position and length. The setter must be used as follows: TXTextControl.selection = { start: 2, length: 5 }

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Property
- **Introduced:** 24.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: TXTextControl.selection Property
- **171 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/txtextcontrol/selection-property/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/txtextcontrol/selection-property/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/txtextcontrol/selection-property/llms-full.txt

---

### Description

Returns the current selection or sets the selection's position and length. The setter must be used as follows: TXTextControl.selection = { start: 2, length: 5 }

### Syntax

```javascript
<Selection> TXTextControl.selection
```

### Examples

The following example demonstrates `TXTextControl.selection` in a practical document-editing workflow. It returns the current selection or sets the selection's position and length. The setter must be used as follows: TXTextControl.selection = { start: 2, length: 5 }.

```javascript
const selection = tXTextControl.selection;
console.log("selection:", selection);
```

---

## Nearby

- **Previous:** [Javascript: TXTextControl.selectAll Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/txtextcontrol/selectall-method/llms-full.txt)
- **Next:** [Javascript: TXTextControl.selectWord Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/txtextcontrol/selectword-method/llms-full.txt)
