1

I am trying to read the html content using innerHTML. It seems to convert the '<' in the text content to '&lt;' .

I would rather not to. Is there anything in JS that would allow me to render as such

  • In HTML, "<" *must* be encoded as `<`. `innerHTML` will give you *valid HTML*. If you're interested in reading the *textual content* of a node, you want `innerText` instead…? – deceze Apr 08 '22 at 06:37

1 Answers1

1

Lodash supports an unescape() function that does this.

For example,

// This reads < as &lt;
let html = document.querySelector('.el').innerHTML
// This converts the &lt; back into <
html = _.unescape(html)

More answers are available in this question: Unescape HTML entities in JavaScript?

S Anand
  • 11,364
  • 2
  • 28
  • 23