I have some simple html editor. Let's say that user types following:
<p>Ok, this just & sucks :) –</p>
and it is saved to some variable:
var content = "<p>Ok, this just & sucks :) –</p>";
Now, somewhere I'm using jQuery to append this text to some element:
$(this).html(content); // where content is the string above
The problem is that it is escaped:
<p>Ok, this just &amp; sucks :) &ndash;</p>
How can I achieve to have the exact string with & ; and &ndash ; and also to have < and not < ; because I need html tags?
Edit: more details added
The problem is not that jQuery is escaping the entities. I think if you use console.log to write the content
string, you'll see that your editor is returning escaped entities to you.
The whole point of .html()
vs .text()
is that .html()
is for HTML that will be treated as HTML.