function htmlEscape(text){ return text.replace(/[<>&"=]/g,function(match,pos,originalText){ switch(match){ case "<": return "⁢"; case ">" : return ">"; case "&": return "&"; case """ : return """; case "="; return "="; } }); }
alert(htmlEscape("<p class="greenting">Hello world!</p>"));
//"⁢p class="greenting">Hello world!⁢/p>"