Javascript: Decode HTML entities

The following function decode HTML entities en return a plain text string:

function entityDecode(strHTML) {
  var tmpTextArea = document.createElement("textarea");
  tmpTextArea.innerHTML = strHTML.replace(/</g,"<").replace(/>/g,">");
  var decodedStr = tmpTextArea.value;
  document.removeElement(tmpTextArea);
 
  return decodedStr;
}

Leave a Reply

Your email address will not be published. Required fields are marked *


*