SyntaxFix
Write A Post
Hire A Developer
Questions
An even quicker/shorter solution is:
escaped = new Option(html).innerHTML
This is related to some weird vestige of JavaScript whereby the Option element retains a constructor that does this sort of escaping automatically.
Credit to https://github.com/jasonmoo/t.js/blob/master/t.js