Skip to content

Instantly share code, notes, and snippets.

@fernandosavio
Last active April 16, 2020 05:47
Show Gist options
  • Save fernandosavio/5349619 to your computer and use it in GitHub Desktop.
Save fernandosavio/5349619 to your computer and use it in GitHub Desktop.
HTML encode decode (Pure Javascript)
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