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 ?
DOM Elements support converting text to HTML by assigning to innerText. innerText is not a function but assigning to it works as if the text were escaped.
document.querySelectorAll('#id')[0].innerText = 'unsafe " String >><>';