I have a regular texbox control. I need to highlight some words with a red color. Is it any possible to do with JavaScript (jquery or anything else)?
A:
No, you can't do that. Your only way would be to use a rich text editor component like FCKEditor or similar.
RichieHindle
2009-05-19 09:24:00
Well, technically you can as all those controls do is to use Javascript on a TextArea element and so forth.
BobbyShaftoe
2009-05-19 09:26:16
rubbish. they are richtext controls. this is a completely different beast to a textarea.
SpliFF
2009-05-19 09:29:17
@SpliFF, so how does TinyMCE work then? Have a look at the example here http://tinymce.moxiecode.com/examples/full.php. It's just a textarea control and a big pile of java script.
Glen
2009-05-19 09:40:50
Tinymce inserts an iframe dynamically and hides the textarea. Use firebug/firefox to see the actual content of a the example and search for 'content_ifr'
KooiInc
2009-05-19 10:22:16
SpliFF is 100% correct: A textbox cannot contain child elements ergo it cannot style individual substrings. End of.
annakata
2009-05-19 10:45:08
thanks for the clarification guys. Makes sense now.
Glen
2009-05-19 11:09:40
+5
A:
Most rich text javascript editors use an iframe
with designMode='on'
since that yields the best cross browser results:
<iframe ID="rtbox"></iframe>
To make the iframe
editable and insert rich text via Javascript you can use the following sample code:
var rtbox = document.getElementById('rtbox');
var doc = rtbox.document ? rtbox.document : rtbox.contentDocument;
doc.designMode = 'on';
doc.body.innerHTML = 'one <span style="color:red">red</span> word';
Josef
2009-05-19 09:47:53
A:
I recommend using TinyMCE for a rich text editor.
And no, what you say is not possible on a normat textarea.
Here Be Wolves
2009-05-19 10:32:32