# Javascript: Selection.changeDirection Method

> Changes the writing direction of all selected paragraphs. When the direction of a paragraph is changed, this paragraph's alignment is toggled from left to right or from right to left. The alignment of centered and justified paragraphs is not changed. Left and right tabulators are also toggled.

- **Product:** DS Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 24.0
- **Path:** DS Server > Reference > JavaScript API > Javascript: Selection.changeDirection Method
- **426 words**
- **Web URL:** https://docs.textcontrol.com/ds-server/reference/javascript/selection/changedirection-method/
- **LLMs URL:** https://docs.textcontrol.com/ds-server/reference/javascript/selection/changedirection-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/ds-server/reference/javascript/selection/changedirection-method/llms-full.txt

---

### Description

Changes the writing direction of all selected paragraphs. When the direction of a paragraph is changed, this paragraph's alignment is toggled from left to right or from right to left. The alignment of centered and justified paragraphs is not changed. Left and right tabulators are also toggled.

### Syntax

```javascript
<void> Selection.changeDirection(<Direction> direction, [<EmptyRequestCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| direction | Specifies the new writing direction of the selected paragraphs. |
| callback | Optional. Is called when the operation completed. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `Selection.changeDirection` in a practical document-editing workflow. It changes the writing direction of all selected paragraphs. When the direction of a paragraph is changed, this paragraph's alignment is toggled from left to right or from right to left. The alignment of centered and justified paragraphs is not changed. Left and right tabulators are also toggled.

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

TXTextControl.selection.changeDirection(
    TXTextControl.Direction.LeftToRight,
    function() {
        console.log("change direction completed.");
    },
    onTxError
);
```

---

## Nearby

- **Previous:** [Javascript: Selection.changeCapitalization Method](https://docs.textcontrol.com/ds-server/reference/javascript/selection/changecapitalization-method/llms-full.txt)
- **Next:** [Javascript: Selection.decreaseIndent Method](https://docs.textcontrol.com/ds-server/reference/javascript/selection/decreaseindent-method/llms-full.txt)
