Skip to content

Instantly share code, notes, and snippets.

@mrroot5
Created May 29, 2015 13:42
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 mrroot5/b552cc0803289d043fa6 to your computer and use it in GitHub Desktop.
Save mrroot5/b552cc0803289d043fa6 to your computer and use it in GitHub Desktop.
function htmlEncode(value){
//create a in-memory div, set it's inner text(which jQuery automatically encodes)
//then grab the encoded contents back out. The div never exists on the page.
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