Reputation: 31
I have a div like
<div id="first"></div>
and I try to change content (which I get from backend html escaped) as
$( "#first" ).html( "Some text <div style="font-size:150%">This text should look bigger</div>" );
----------OR------------
$( "#first" ).html( "Some text <div style="font-size:150%">This text should look bigger</div>" );
The output in browser is
<div id="first">Some text <div style=""font-size:150%"">This text should look bigger</div></div>
This is not applying the style I wanted to apply as in the DOM I see two times " (quote). I also tried the classic way of document.getElementById with out any success.
Thank's in advance for any idea.
Upvotes: 0
Views: 395
Reputation: 2830
You can decode escaped text with this function:
function htmlDecode(value) {
if (value) {
return $('<div />').html(value).text();
} else {
return '';
}
}
You should pass escaped HTML from the backend through this function before writing it to the page.
Upvotes: 1