Skip to content

Instantly share code, notes, and snippets.

@ryanburgess
Created January 7, 2014 01:26
Show Gist options
  • Select an option

  • Save ryanburgess/8293219 to your computer and use it in GitHub Desktop.

Select an option

Save ryanburgess/8293219 to your computer and use it in GitHub Desktop.
JavaScript HTML escaper function
function escapeHTML(text) {
var replacements= {"<": "&lt;", ">": "&gt;","&": "&amp;", "\"": "&quot;"};
return text.replace(/[<>&"]/g, function(character) {
return replacements[character];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment