An Interest In:
Web News this Week
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
April 14, 2022 02:37 am GMT
Original Link: https://dev.to/lionelrowe/easily-and-safely-escape-html-in-one-line-4lak
Easily and safely escape HTML in one line
x => Object.assign(document.createElement('div'), { textContent: x }).innerHTML
True, you could also do it with
x => x.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'")
or similar, but if you do it the first way you don't have to remember the HTML entities
Original Link: https://dev.to/lionelrowe/easily-and-safely-escape-html-in-one-line-4lak
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To