2 ms·
I like to use a small utility function like this and pass user input through it. function asTextContent(input) { const tempElement = document.createEleme
by MzHN 3y ago
I like to use a small utility function like this and pass user input through it.
function asTextContent(input) {
const tempElement = document.createElement('span');
tempElement.textContent = input;
return tempElement.innerHTML;
}
It will let the browser handle the escaping.