Through English OS searches, I learned how to decode and encode HTML entities as follows:
var wm = (function(wm){
wm.encodeHTML = function (html) {
var t = document.createElement('textarea');
t.innerHTML = html;
return t.innerHTML;
}
wm.decodeHTML = function (html) {
var t = document.createElement('textarea');
t.innerHTML = html;
return t.value;
}
}({}));
I'd like a more elegant solution (regular expression or whatever) to convert HTML entities, rather than creating a textarea
and returning the value of it.
Can anyone help?