javascript - Not able to render HTML tags inside textarea content - Stack Overflow

I have a HTML file with textarea input element and the content is fetched from database which includes

I have a HTML file with textarea input element and the content is fetched from database which includes <br/> tags.

My JSON response is:
NDAs can be "mutual", meaning both parties are restricted in their use of the materials provided, or they can restrict the use of material by a single party. <br /> It is also possible for an employee to sign an NDA or NDA-like agreement with an employer.

On rendering it is not taking a new line and displaying <br/> as it is(taking as static content). I used handlebars {{{content}}} but not helpful.

I have a HTML file with textarea input element and the content is fetched from database which includes <br/> tags.

My JSON response is:
NDAs can be "mutual", meaning both parties are restricted in their use of the materials provided, or they can restrict the use of material by a single party. <br /> It is also possible for an employee to sign an NDA or NDA-like agreement with an employer.

On rendering it is not taking a new line and displaying <br/> as it is(taking as static content). I used handlebars {{{content}}} but not helpful.

Share edited Mar 28, 2017 at 7:08 Lahiru 1,69815 silver badges20 bronze badges asked May 11, 2015 at 8:05 ArchanaArchana 1033 silver badges12 bronze badges 2
  • You can't render html into a textarea, but you can force line breaks replacing <br> tags by \n or \r. To be sure, use a regex into replace function: yourString = yourString.replace(/\r?\n/g, '') – kosmos Commented May 11, 2015 at 8:12
  • Did you try encoding your HTML? Like <br> bees &lt;br&gt;? – Salman Arshad Commented May 11, 2015 at 8:52
Add a ment  | 

3 Answers 3

Reset to default 2

You simply can't enter HTML inside a textarea, you can only insert pure text.

You may want to use an editable div (<div contenteditable="true">...</div>)

Ref. https://developer.mozilla/en-US/docs/Web/Guide/HTML/Content_Editable

If you want that your HTML will be rendered, you should use contenteditable to do so.

You can try replacing <br /> with /n. That should resolve your issue.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744649407a4585810.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信