How do i unescape HTML Entities in JS? (change &lt; to <) [duplicate]

How do i unescape HTML Entities in JS?

When googling i literally saw answers with a huge switch and people rolling their own.

I'd like the string &lt;html xmlns=&quot;; &gt; to become <html xmlns="" >



Create a div, set it's innerHTML and then read innerText

var d = document.createElement("div");
d.innerHTML = "&lt;html xmlns=&quot;; &gt;";
alert(d.innerText || d.text || d.textContent);

Here is a JS implementation of a PHP function that decodes HTML entities

Note that this function also depends on:


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.