# Writing a string to textarea without markup in JS

**URL:** <https://forum.kirupa.com/t/writing-a-string-to-textarea-without-markup-in-js/638797>\
**Category:** programming\
**Created:** [October 11, 2018, 8:44pm UTC](https://forum.kirupa.com/t/writing-a-string-to-textarea-without-markup-in-js/638797 "2018-10-11T20:44:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_Clarke](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@T\_Clarke](https://forum.kirupa.com/u/T_Clarke)\
**Post date:** [October 11, 2018, 8:44pm UTC](https://forum.kirupa.com/t/writing-a-string-to-textarea-without-markup-in-js/638797/1 "2018-10-11T20:44:16Z")

</div>

Hi

I am trying to selectively colour text, according to word length. I have achieved a string with markup included, e.g. \< font color=“green”\>\< font\>

My problem is how do I write this, programmatically, to a text area (already included in a form div) as a normal string, appropriately coloured, without the markup? I can do that with document.write()… but that is not very elegant, and also loses paragraph divisions.  
Any help or advice is welcome. Tony.

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [October 12, 2018, 8:59pm UTC](https://forum.kirupa.com/t/writing-a-string-to-textarea-without-markup-in-js/638797/2 "2018-10-12T20:59:04Z")

</div>

Tony, do you absolutely have to have the text inside a textarea? AFAIK, you can’t change the color of individual segments inside a textarea element. The way you see many popular text editors accomplish something similar is by using `span` elements inside a `div`.

---

<div class="post-metadata">

**Author:** ![T\_Clarke](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@T\_Clarke](https://forum.kirupa.com/u/T_Clarke)\
**Post date:** [October 13, 2018, 3:54pm UTC](https://forum.kirupa.com/t/writing-a-string-to-textarea-without-markup-in-js/638797/3 "2018-10-13T15:54:45Z")

</div>

Thanks Kirupa, no but that seemed the way to do it. I wrote a program in Python to do this, which modifies the text in place within a Tkinter text box. In trying to replicate that in JS, I extracted the contents which the user pastes into a text area, then manipulated it using changecolour(). But I don’t know where to put the resulting changed string, text area doesn’t accept it.

I will research the span/div approach, but as a relative newcomer to JS it would help if you could point me to an example, i.e. modifying the colour of user-input text within strings, and showing this again with only the colour changed.

Many thanks for your help

Tony
