Rendering HTML inside textarea

后端 未结 7 1847
孤独总比滥情好
孤独总比滥情好 2020-11-22 01:34

I need to be able to render some HTML tags inside a textarea (namely , , , ) but textareas only interpret their content as text. Is

相关标签:
7条回答
  • 2020-11-22 02:23

    I have the same problem but in reverse, and the following solution. I want to put html from a div in a textarea (so I can edit some reactions on my website; I want to have the textarea in the same location.)

    To put the content of this div in a textarea I use:

    var content = $('#msg500').text();
    $('#msg500').wrapInner('<textarea>' + content + '</textarea>');
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <div id="msg500">here some <strong>html</strong> <i>tags</i>.</div>

    0 讨论(0)
提交回复
热议问题