Skip to content

Instantly share code, notes, and snippets.

@dpnishant
Created September 20, 2013 11:45
Show Gist options
  • Save dpnishant/6636322 to your computer and use it in GitHub Desktop.
Save dpnishant/6636322 to your computer and use it in GitHub Desktop.
htmlEncoder
function htmlEncode(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML.replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/").replace(/`/g,"`");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment