javascript - How to parse HTML tags from JSON Object -


i have json object has value of html styles. tried including in html using jquery append.

the value getting appending, not converting normal dom, appending whole thing string.

this json object value:

 var obj = {     content : "<p>&lt;linkrel=&quot;stylesheet&quot;type=&quot;text/css&quot;href=&quot;http:<p>&lt;styletype=&quot;text/css&quot;&gt;<br/>.wrap{<br/>&nbsp;&nbsp;background-color:#f6f6f6;<br/>}<br/>&lt;/style&gt;</p><p>&lt;divclass=&quot;wrap&quot;&gt;<br/>    &lt;/div&gt;</p>" }   

this tried:

html:

<div id='container'></div> 

js:

$('#container').append(obj.content); 

demo

output should part of dom, instead printing entire thing string.

you can ...

var obj = {     content : '<p>&lt;style&gt;.wrap{color:red}&lt;/style&gt;&lt;div class="wrap"&gt;aa&lt;/div&gt;</p>' }   $('span').append($(document.createelement('div')).html(obj.content).text()); 

fiddler: https://jsfiddle.net/suscmguy/

your obj.content seems have invalid / incomplete encoding

hope helps...


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -