Skip to content

Instantly share code, notes, and snippets.

@mynameispj
Created February 3, 2013 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mynameispj/4703553 to your computer and use it in GitHub Desktop.
Save mynameispj/4703553 to your computer and use it in GitHub Desktop.
HTML Special Characters in jQuery
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
@rafis
Copy link

rafis commented Feb 15, 2014

I dont see jQuery here, only pure JavaScript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment