Created
March 28, 2018 08:34
-
-
Save johnw86/f0d88e65d5f96ac4c67647e9bff205de to your computer and use it in GitHub Desktop.
JavaScript functions to encode and decode html
This file contains hidden or 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
| 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