Skip to content

Instantly share code, notes, and snippets.

@mllrjb
Created June 5, 2014 20:47
Show Gist options
  • Save mllrjb/2b536982fecc4b0554de to your computer and use it in GitHub Desktop.
Save mllrjb/2b536982fecc4b0554de 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