Created
September 5, 2015 19:22
-
-
Save matesnippets/99bd3ef014b45da66415 to your computer and use it in GitHub Desktop.
JavaScript, escape a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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