Skip to content

Instantly share code, notes, and snippets.

@johnw86
Created March 28, 2018 08:34
Show Gist options
  • Select an option

  • Save johnw86/f0d88e65d5f96ac4c67647e9bff205de to your computer and use it in GitHub Desktop.

Select an option

Save johnw86/f0d88e65d5f96ac4c67647e9bff205de to your computer and use it in GitHub Desktop.
JavaScript functions to encode and decode html
function htmlEncode(html) {
return document.createElement('div').appendChild(
document.createTextNode(html)).parentNode.innerHTML;
};
function htmlDecode(html) {
var div = document.createElement('div');
div.innerHTML = html;
return div.textContent;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment