Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple HTML encoding/decoding using jQuery
// 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();
}
@Lukenickerson

This comment has been minimized.

Copy link

@Lukenickerson Lukenickerson commented Dec 15, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment