18

I don't want this:

<textarea>The <b>color</b> is black.</textarea>

Instead of the <b> and </b> i want the text "color" to be shown in bold.

Is this possible?

Jo Smo
  • 6,923
  • 9
  • 47
  • 67
  • As far I know textareas don't accept any HTMLy only pure text if you're not using any jQuery / JS tools or plugins. – cybrox Jul 03 '13 at 19:14
  • 1
    you need a rich text editor - see http://stackoverflow.com/questions/8903525/rich-text-html-editor-for-websites-i-can-use-for-free – Jason Jul 03 '13 at 19:17
  • 2
    I think this is what you wanted: http://stackoverflow.com/questions/4705848/rendering-html-inside-textarea answered by @Marcus Ekwall take a look at his [jsfiddle](http://jsfiddle.net/mekwall/XNkDx/) – Timber Jul 03 '13 at 19:17
  • codemirror will let you do this while still acting like a textarea instead of a div... that's to say that the .value will not have the presentational markup, not sure if you want it just shown or actually integrated into the string. – dandavis Jul 03 '13 at 19:19
  • If you want to do it yourself, I couldn't think of any other solution. But as others pointed out, I think you might want to use a WYSIWYG html editor plugin. such as [this](http://imperavi.com/redactor/). – Timber Jul 03 '13 at 19:26
  • @tastro No worries, as long as you got what you need :) – Timber Jul 03 '13 at 22:50

2 Answers2

19

You Can't style the content of a text area separately, you have to use <div>s, or something similar. This may be a duplicate of:

Format text in a <textarea>?

Do you Want Something like this:?

http://jsfiddle.net/mekwall/XNkDx/

$('.editable').each(function(){
    this.contentEditable = true;
});

this allows you to edit the content of a div, and it will still look like a textarea,

Bold Works.

Community
  • 1
  • 1
Deep
  • 920
  • 8
  • 22
5

For these cases, avoid use something pure text area, use wysiwyg html editor.

Here are some ideas for you:

ckeditor

niceditor

lucianosousa
  • 8,144
  • 4
  • 21
  • 25
  • 1
    @tastro, I really don't recommend because tomorrow you need configure italic/border/etc, then, it's better prevent using these editors. – lucianosousa Jul 03 '13 at 19:54