Created
September 5, 2013 04:00
-
-
Save js1972/6445942 to your computer and use it in GitHub Desktop.
#JavaScript for #html encoding and decoding a value with #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
/* | |
Use jQuery to html encode a value | |
*/ | |
function htmlEncode(value){ | |
//create a in-memory div, set its 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(); | |
} | |
/* | |
Use jQuery to html decode a vlaue | |
*/ | |
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