In my utility belt, this tiny function is always:
function htmlDecode(input){ var e = document.createElement('div'); e.innerHTML = input; return e.childNodes[0].nodeValue; } htmlDecode("&");
It will work for all HTML objects .
Edit: Since you are not in a DOM environment, I think you will have to do this using the βhardβ way:
function htmlDecode (input) { return input.replace(/&/g, "&") .replace(/</g, "<") .replace(/>/g, ">");
If you don't like tethered replacements, you can create an object to store your objects, for example:
function htmlDecode (input) { var entities= { "&": "&", "<": "<", ">": ">" //.... }; for (var prop in entities) { if (entities.hasOwnProperty(prop)) { input = input.replace(new RegExp(prop, "g"), entities[prop]); } } return input; }
CMS
source share