Skip to content

Instantly share code, notes, and snippets.

@matesnippets
Created September 5, 2015 19:22
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 matesnippets/99bd3ef014b45da66415 to your computer and use it in GitHub Desktop.
Save matesnippets/99bd3ef014b45da66415 to your computer and use it in GitHub Desktop.
JavaScript, escape a string
/**
* Use the browsers native capability to escape strings
*/
'use strict';
define(function() {
// Use the browser's built-in functionality to quickly and safely escape the
// string
return function(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment