I have been searching the web for a javascript function that turns something like this:
Hi.&nbsp; I will show <span style="font-weight: bold;">HTML</span>.
Into this:
Hi. I will show <span style="font-weight: bold;">HTML</span>.
I am using this method:
htmlDecode: function (input) {
var doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent;
}
And it works the first time. But if I try it again, on text like this:
Hi. I will show <span style="font-weight: bold;">HTML</span>
It strips out all the html and just leaves me with:
Hi. I will show HTML.
I only want the method to change this:
Hi.&nbsp; I will show <span style="font-weight: bold;">HTML</span>.
Into this:
Hi. I will show <span style="font-weight: bold;">HTML</span>.
I don't want it to totally strip out the HTML.
Is there a way to do that?
Thanks!