id like to decode all HTML Entities from a String (named descr, coming from a MySQL-DB)
I use this function to do this:
function htmlDecode(input) {
var doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent;
}
And this works fine, if i print the value to a div.
document.getElementById('ABC').innerHTML = htmlDecode(descr); -> Descr = "&" -> Output in Div "&"
But if i print the value to a textarea its not decoded:
document.getElementById('ABCD').value = htmlDecode(descr); -> Descr = "&" -> Output in Textarea "&"
I spend ours in SO, but didtn find a solution. Can you help me?
innerHTMLis placing actual HTML into the element, which is being interpreted by the browser to show cleanly.valueof a textarea is placing raw text. What happens when you do NOT decode it for the textarea?&into a div, it will render that to just&... if you put it in a textbox (or textarea) it will literally show&