Reputation: 1369
I have a textarea where i need to set some html text
<textarea id="text"></textarea>
<div id="elem">
<p>text</p>
<hr />
<br />
<p> some text</p>
</div>
..
$('#text').val($('#elem').html());
when I do this it's put text with html tags instead of parse it and put like a plain text.
i also tried functions append(), html(), text()
. none of them helps me
Upvotes: 0
Views: 910
Reputation: 335
text()
worked for me. See https://jsfiddle.net/mgLp90em/.
What is the jQuery version you are using?
Upvotes: 1
Reputation: 6467
I'd recommend to use a contenteditable
div
element instead of a textarea
as follows:
<div class="text-area" contenteditable>
<h1>Your content here</h1>
</div>
See JSfiddle demo
Upvotes: 0
Reputation: 5958
This should do the trick, gets only text from the children within your #elem
:
$('#text').val($('#elem').children().text());
Upvotes: 0