# Dynamically change color of selected text

**URL:** https://forum.kirupa.com/t/dynamically-change-color-of-selected-text/175325
**Category:** Uncategorized
**Created:** [January 13, 2006, 12:53pm UTC](https://forum.kirupa.com/t/dynamically-change-color-of-selected-text/175325 "2006-01-13T12:53:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jerryj](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jerryj](https://forum.kirupa.com/u/jerryj)
#### Post date: [January 13, 2006, 12:53pm UTC](https://forum.kirupa.com/t/dynamically-change-color-of-selected-text/175325/1 "2006-01-13T12:53:44Z")

</div>

Hi,

how can I change the color of a selected piece of text dynamically?

I tried somethings like this (the function is called by a button):

```auto
function changeColor() {
    Selection.setFocus(textFieldname);
    Selection.setSelection(begin, end);
        sel = textFieldname.text.slice(begin, end);
    sel.textColor = "0xFF0000";
}

```

but I guess ‘sel’ isn’t a string, so i can’t add textColor to it?

Adding something like:

```auto
sel = new String(begin, end);

```

doesn’t help much.

thank you,

Jerryj.

---

<div class="post-metadata">

### Author: ![mastamokei](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@mastamokei](https://forum.kirupa.com/u/mastamokei)
#### Post date: [June 21, 2008, 2:20am UTC](https://forum.kirupa.com/t/dynamically-change-color-of-selected-text/175325/2 "2008-06-21T02:20:23Z")

</div>

Hi,  
Did you ever get this to work? I’m trying it with that code and can’t get it to work. Could you post the code up again?
