Last active
August 29, 2015 14:21
-
-
Save k4zuki02h4t4/fd5e7cb6ba7598e413d0 to your computer and use it in GitHub Desktop.
JavaScript escape HTML.
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
var escapeQuotHTML = function(str){ | |
return str.replace(/&/g,'&').replace(/"/g, '"').replace(/\'/g, ''').replace(/</g,'<').replace(/>/g,'>'); | |
}; | |
var escapeHTML = function(str){ | |
var div = document.createElement('div'); | |
var text = document.createTextNode(str); | |
div.appendChild(text); | |
return div.innerHTML; | |
}; | |
var deleteHTML = function(str){ | |
return str.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g, ''); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment