Created
May 31, 2022 09:32
-
-
Save teocci/69921c8c24bc0c5cfeea6ed93b56429d to your computer and use it in GitHub Desktop.
HTML encode decode (Pure Javascript)
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
function html_decode(text){ | |
var div = document.createElement("div"); | |
div.innerHTML = text; | |
return ("textContent" in div) ? div.textContent : div.innerText ; | |
} | |
function html_encode(str){ | |
var div = document.createElement("div"); | |
div[("textContent" in div) ? "textContent" : "innerText"] = str; | |
return div.innerHTML; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment