Skip to content

Instantly share code, notes, and snippets.

@yaph
Created January 21, 2012 19:37
Show Gist options
  • Save yaph/1653688 to your computer and use it in GitHub Desktop.
Save yaph/1653688 to your computer and use it in GitHub Desktop.
Fast HTML tag escape JavaScript function
// see benchmark at http://jsperf.com/encode-html-entities
String.prototype.escapeHTML = function(){
var div = document.createElement('div');
div.appendChild(document.createTextNode(this));
return div.innerHTML;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment