1function escapeHtml(str) {
2 return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
3}
1//escaping HTML with jquery
2var dangerousHTML = "<script>alert('Badabing Baby!');</script>";
3$("#myElementID").text(dangerousHTML); //.text() function will escape and display text
4
5
6//Alternatively, here is plain Javascript escape function
7function escapeHtml(str) {
8 return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
9}