Created
August 1, 2012 02:21
-
-
Save jmblog/3222899 to your computer and use it in GitHub Desktop.
Simple HTML encoding/decoding using jQuery
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
// http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding | |
function htmlEncode(value){ | |
return $('<div/>').text(value).html(); | |
} | |
function htmlDecode(value){ | |
return $('<div/>').html(value).text(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A more reliable method is to use
.replace
to replace the problematic characters, as shown in this example and used by Angular. See this article for more details.