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

html, javascript

Solution

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

var d = document.createElement("div");
d.innerHTML = "&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;";
alert(d.innerText || d.text || d.textContent);

Problem

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;http://www.w3.org/1999/xhtml&quot; &gt;` to become `<html xmlns="http://www.w3.org/1999/xhtml" >`

Original source

Related problems