I want to convert <p> ... <code>&lt;div id='asd'&gt;asd&lt;/div&gt;</code></p>
to <p> ... <code><div id='asd'>asd</div></code></p>
with jquery.
In other saying I want to apply using jquery what @Html.Raw(HttpUtility.HtmlDecode(html))
does as in asp.net MVC.
I tried the solutions of similar problems(link1, link2), but they aren't enough to solve my problem. There occured two problems; replace doesn't replace all matching as in this fiddle (I solved this problem with this link); and the converted code isn't shown as expected in html and browser. Hierarchy of html is destroyed.
for detail:
The string to be decoded:
<p>fddfg dfgdfgdfg dfgdfgdfgd <em>asdasd</em> <strong>cvbncvbn</strong> <code>&lt;div id='asd'&gt;asd&lt;/div&gt;</code></p>
Html output after html decode:
<p>
fddfg dfgdfgdfg dfgdfgdfgd
<em>asdasd</em>
<strong>cvbncvbn</strong>
<code></code>
</p>
<div id="asd">
<code>asd</code>
</div>
<p></p>
Browser output after html decode:
fddfg dfgdfgdfg dfgdfgdfgd asdasd cvbncvbn
asd
You can see the problem in fiddle (look at, especially at console):
Expected or desired browser output:
fddfg dfgdfgdfg dfgdfgdfgd asdasd cvbncvbn <div id='asd'>asd</div>
Why this broken html output comes out and how can I solve this?