Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

how to unescape in html

Unescaping HTML in a string by replacing:
&lt; with <
&gt; with >
&quot; with "
&#39; with '
&amp; with &
  -----------------------------------
  function unEscape(htmlStr) {
    htmlStr = htmlStr.replace(/&lt;/g , "<");	 
    htmlStr = htmlStr.replace(/&gt;/g , ">");     
    htmlStr = htmlStr.replace(/&quot;/g , """);  
    htmlStr = htmlStr.replace(/&#39;/g , "'");   
    htmlStr = htmlStr.replace(/&amp;/g , "&");
    return htmlStr;
}

let unEscapedStr =unEscape(`&lt;script&gt;alert(&#39;hi&#39;)&lt;/script&gt;`);
console.log(unEscapedStr);
 
PREVIOUS NEXT
Tagged: #unescape #html
ADD COMMENT
Topic
Name
5+8 =