Reputation: 1167
Curious problem. I need to empty a <textarea>
then replace it with other content. The tests in the JSFiddle will work if nothing is manually typed, but as soon as anything is entered in the textarea by hand, the methods will cease to work.
I understand that I can simply just .val('New stuff here')
, however I need HTML entities such as >
and <
to appear as <
and >
, which .val() will not accomplish.
Upvotes: 1
Views: 118
Reputation: 42468
It sounds like your real problem is that you want to decode HTML entities to render them in a text area. You could use the following to do this:
var content = 'text > HTML';
$('#myText').val($('<div/>').html(content).text());
However, you should only do this with trusted content. If the content for the textarea is not created by you, it could contain malicious HTML, which you would unsafely be creating on the page.
For a more thorough example, see this answer to essentially the same question; note that the accepted answer repeats the above, but the linked answer is safer.
Upvotes: 3