I want to display a text to HTML by a javascript function. How can I escape html special chars in JS? Is there an API ?
function escapeHtml(unsafe) { return unsafe .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); }