Apparently, this is harder to find than I thought it would be. And it even is so simple...
Is there a function equivalent to PHP\'s htmlspecialchars built into Javas
function htmlspecialchars(str) { if (typeof(str) == "string") { str = str.replace(/&/g, "&"); /* must do & first */ str = str.replace(/"/g, """); str = str.replace(/'/g, "'"); str = str.replace(//g, ">"); } return str; }