Sometimes, we want to sanitize or rewrite HTML on the client side with JavaScript.
In this article, we’ll look at how to sanitize or rewrite HTML on the client side with JavaScript.
How to sanitize or rewrite HTML on the client side with JavaScript?
To sanitize or rewrite HTML on the client side with JavaScript, we can use the sanitize-html package.
To install it, we run
npm install --save sanitize-html
Then we write
import sanitizeHtml from "sanitize-html";
//...
const sanitized = sanitizeHtml(htmlInput);
to import the sanitizeHtml function and call it with the htmlInput HTNL string to return a sanitized version of the string.
Conclusion
To sanitize or rewrite HTML on the client side with JavaScript, we can use the sanitize-html package.