0

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=&#34;font-size:150%&#34;>This text should look bigger</div>" ); 

----------OR------------

$( "#first" ).html( "Some text <div style=&quot;font-size:150%&quot;>This text should look bigger</div>" ); 

The output in browser is

<div id="first">Some text <div style="&quot;font-size:150%&quot;">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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The problem is the server is giving him &quot;. escaping it with \ on the client side won't fix that. I'd suggest making it clear that this solution requires modification of how the server is returning the data (if that's what you're suggesting)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.