Skip to content

Instantly share code, notes, and snippets.

@mynameispj
Created February 3, 2013 20:35
Show Gist options
  • Select an option

  • Save mynameispj/4703553 to your computer and use it in GitHub Desktop.

Select an option

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

rafis commented Feb 15, 2014

Copy link
Copy Markdown

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