I have some Javascript code that communicates with an XML-RPC backend. The XML-RPC returns strings of the form:
jQuery will encode and decode for you. However, you need to use a textarea tag, not a div.
var str1 = 'One & two & three';
var str2 = "One & two & three";
$(document).ready(function() {
$("#encoded").text(htmlEncode(str1));
$("#decoded").text(htmlDecode(str2));
});
function htmlDecode(value) {
return $("").html(value).text();
}
function htmlEncode(value) {
return $('').text(value).html();
}