Last active
May 19, 2020 18:26
-
-
Save MaraScott/4571523 to your computer and use it in GitHub Desktop.
Name : htmlEncode("text"), htmlDecode("text") - Language : JavaScript, jQuery - type : function - platform : generic
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?answertab=votes#tab-top | |
function htmlEncode(value){ | |
"use strict"; | |
//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){ | |
"use strict"; | |
return $('<div/>').html(value).text(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment