Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JavaScript - Escape HTML

#JavaScript - Escape HTML

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
You can’t perform that action at this time.