Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you have an html list inside a <textarea> and it look like a list?

I tried

<textarea rows="10" columns="2"><li>joe</li><li>jerry</li></textarea>

to see if I could put an html list in a <textarea> but it just showed as text. Is there any way to show it as a list inside the textarea?

like image 523
chromedude Avatar asked Dec 09 '25 22:12

chromedude


1 Answers

You can't have HTML inside textareas - it's for plain text only. However, you can try using contentEditable for this. The result isn't very good, but you be the judge whether you want to use it or not. Simply use something like this:

<div class="editable" contenteditable="true">
    <ul>
        <li>List item</li>
        <li>List item</li>
    </ul>
</div>

The problems with this method is that it's difficult to predict what HTML the browser will produce, and that some of the HTML produced are truly atrocious, and that you'll have to sanitise the input a lot more than using plain text. Also, the interface for this isn't specified in the specifications, so you'll be dealing with different interfaces in different browsers.

See: http://www.jsfiddle.net/yijiang/bN2tm/ and http://html5demos.com/contenteditable

like image 143
Yi Jiang Avatar answered Dec 12 '25 11:12

Yi Jiang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!