I want to display a text to HTML by a javascript function. How can I escape html special chars in JS? Is there an API ?
The most concise and performant way to display unencoded text is to use textContent property.
textContent
Faster than using innerHTML. And that's without taking into account escaping overhead.
innerHTML
document.body.textContent = 'a c ';