Reputation: 531
I'm using this jQuery command:
$('.body-container').append(bodyPart.content).html();
to append HTML content into my body. If "bodyPart.content" is something like:
<strong>Bold</strong>
It works nicely, and show me on my browser:
Bold
But if it's:
<strong> Bold </strong>
it shows me on the browser:
<strong> Bold </strong>
What to do here to jQuery understand escaped HTML code?
Upvotes: 2
Views: 2667
Reputation: 2322
You can replace the <
and >
with the proper characters using replace like so:
$("button").click(function(){
var inp = $("input").val().replace(/</gi,"<").replace(/>/gi,">");
$('.body-container').append(inp).html();
});
https://jsfiddle.net/IronFlare/w7edc0cv/
With the help of this question, I think I may have managed to solve your issue (hopefully):
$("button").click(function(){
$('.body-container').append($('<div/>').html($("input").val()).text());
});
https://jsfiddle.net/IronFlare/w7edc0cv/3/
Upvotes: 1