Getting internal html without escaping or decoding anything with jQuery

I am developing some kind of html online editor and I have a problem getting the contents of the text area using jQuery.

The Textarea element is as follows:

<textarea id="myText"><b>&lt;p&gt;TEST&lt;/p&gt;</b></textarea> 

So this is a mixture of shielded and unshielded text. However, the browser displays text space similar to this, which is also not needed:

 <b><p>TEST</p></b> 

I want to get the internal html of the text field as is. If I try .html() , it will escape all tags, and if I try .val() , it will decode escaped tags. You can see the behavior of http://jsfiddle.net/hnBte/

How can I get pure content using Javascript and, if desired, how can I make textarea display the content as is?

thanks

+4
source share
4 answers

I found this really interesting question, so I did some research: I tried all the javascript and jQuery functions to see what I get, but nothing worked. You can only get fully unparsed or fully parsed html.

I also stumbled upon this SO question, which also confirms that, unfortunately, it is simply impossible to do: Getting the source text content of an HTML element with an HTML interpreter .

+5
source

Try the .text() method in jQuery. http://api.jquery.com/text/

0
source

Can't you use standard JavaScript .innerHTML ?

Here's a related post about the differences between JavaScript .innerHTML and jQuery .HTML() fooobar.com/questions/82417 / ...

0
source

Capture input when the user enters it, or when you download it from an external source.

0
source

All Articles