Skip to content

Instantly share code, notes, and snippets.

@danbrianwhite
Last active November 16, 2015 18:38
Show Gist options
  • Save danbrianwhite/bec32f20d5eac7c4e5fa to your computer and use it in GitHub Desktop.
Save danbrianwhite/bec32f20d5eac7c4e5fa to your computer and use it in GitHub Desktop.
Enocde a JS string to be used in an HTML element's attritube
String.prototype.encodeTag = function () {
return this.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment