# Javascript: Selection.getForeColor Method

> Gets the color used to display the selected text.

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

---

### Description

Gets the color used to display the selected text.

### Syntax

```javascript
<void> Selection.getForeColor(<RequestStringCallback> callback, [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| callback | Is called with the color used to display the selected text. The color attribute is if available the color's name else the HEX value as a string. The property's default value is the HTML Color windowtext. The property returns its default value when the text selection contains multiple characters with mixed colors. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `Selection.getForeColor` in a practical document-editing workflow. It gets the color used to display the selected text.

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

TXTextControl.selection.getForeColor(
    function(result) {
        console.log("get fore color result:", result);
    },
    onTxError
);
```

---

## Nearby

- **Previous:** [Javascript: Selection.getFontSize Method](https://docs.textcontrol.com/ds-server/reference/javascript/selection/getfontsize-method/llms-full.txt)
- **Next:** [Javascript: Selection.getFormattingStyle Method](https://docs.textcontrol.com/ds-server/reference/javascript/selection/getformattingstyle-method/llms-full.txt)
