I am developing some kind of online html editor and I have a problem with getting the content of a textarea with jQuery.
The Textarea element is like this:
<textarea id="myText"><b><p>TEST</p></b></textarea>
So it is a mixture of escaped and unescaped text. However, the browser shows the textarea like this, which is also something that I don't want :
<b><p>TEST</p></b>
I want to get the inner html of the textarea as it is. If I try .html()
, it escapes all the tags and if I try .val()
, it decodes the escaped tags. You can see the behavior at http://jsfiddle.net/hnBte/
How can I get the pure content with Javascript and optionally, how can I make the textarea show the content as it is?
Thanks
I found this a really interesting question, so I did some research: I tried all javascript and jQuery functions to see what I would get, but nothing worked. You can only get completely unparsed or completely parsed html.
I also stumbled upon this SO-question, that also confirms that, sadly, it just can't be done: Getting raw text content of HTML element with HTML uninterpreted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With