Skip to content Skip to sidebar Skip to footer

Javascript - Change Font Color Of Certain Text In Textarea

Is there any JS function that can change the color of certain text in a textarea? For example, blar blar {blar} blar, {blar}, including { }, will be in blue. Other words will be in

Solution 1:

No one mentioned contentEditable? Just make a contentEditable div and use javascript to style it. I reccommend you to look into the Dojo Toolkit's. It has a Editor widget.

Other resources: Some contentEditable problems in IE.How to use contentEditable with jQuery or without it.

Solution 2:

wysiwig-editors are using iframes instead of textareas. Textareas are very little customizable, since what you're after is changing part of the content. You can't add tags inside a textarea, which makes it impossible to only change part of the text.

If you look at the editor here in SO, you write normal text inside a textarea, and it is then transformed in the box below it, so you'll see the asterix inside the textbox, but in the box below, it'll transform special characters by regexing them with tags.

If you're using firebug, you can start writing inside the editor, while looking at the HTML in the preview-box.

Solution 3:

you can't use a textarea to do that, per se.

But, javascript is your friend. Perhaps you should take a look at the code of a few rich text editors.

You could start with lwrte, since it says its "lightweight". Also, its written in jquery so it will be pretty easy to undertand. (and I'm a jquery fanboy).

Hope that helps,

jrh

Solution 4:

I Think You will need to use execCommand method of javascript it controls many thing such this stuff of changing specifc textcolor

Regards

Solution 5:

But some Jquery WYSIWYG editors do this ! How is that possible ? See this editor lwrte

Post a Comment for "Javascript - Change Font Color Of Certain Text In Textarea"