views:

153

answers:

1

How to Change the Color Of Certain Words In Textarea using Jquery ?

For instance, i have a textarea <textarea id="txt"> </textarea>

When i type into the textarea, certain words like "is, a , was ..." should be colored or highlighted.

The aim is to create a ultra simple HTML syntax highlighter for my project that's all !

+3  A: 

This is completely impossible.

You need to use a content-editable <iframe>.

The reason it's not possible is that the <TEXTAREA> has no ability, in any browser, to support formatting. You need a differnt kind of element, so that words can be wrapped in elements, formatting the text.

SLaks
Edited answer to explain *why* it's not possible.
Ian Boyd
But some editors like lwrte use textarea to color text
Aakash Chakravarthy
They use ContentEditable elements, not `<textarea>`s.
SLaks
Then how to do with that ?
Aakash Chakravarthy
@Aakash: Have a look at the sources of [JS Bin](http://jsbin.com/) at http://github.com/remy/jsbin and see what it uses for coloring the HTML.
Marcel Korpel