Coder Perfect

HTML rendering in a textarea

Problem

I need to be able to render specific HTML tags (particularly strong>, I u>, and a>) within a textarea, however textareas only interpret their content as text. Is there a simple method to do that without relying on third-party libraries or plugins (I’m using jQuery)? If not, do you know of any jQuery plugins that I might use?

Asked by The Coding Monk

Solution #1

With a textarea, this is not possible. You’re seeking for a content editable div, which is simple to create:

<div contenteditable="true"></div>

jsFiddle

Answered by mekwall

Solution #2

The method document can be used with an editable div. execCommand (details) to quickly offer support for the tags you supplied, as well as several additional features.

Answered by Sampath Liyanage

Solution #3

Yes, you can, as you merely said render. You may try something similar to this:

Answered by merlin

Solution #4

try this example

Answered by david grinstein

Solution #5

I’d like to contribute something to this. You can utilize character entities to render in the textarea (for example, altering div> to div>). When it’s saved, though, the textarea’s value is the rendered text. As a result, there is no need to decode. I just tried it in a few other browsers (ie back to 11).

Answered by axlotl

Post is based on https://stackoverflow.com/questions/4705848/rendering-html-inside-textarea