Skip to content

Instantly share code, notes, and snippets.

@teocci
Created May 31, 2022 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teocci/69921c8c24bc0c5cfeea6ed93b56429d to your computer and use it in GitHub Desktop.
Save teocci/69921c8c24bc0c5cfeea6ed93b56429d 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