I chucked together a function that allows some tags to be kept, similar to how the php function works.
As with PHP it comes with the following two caveats:
Because strip_tags() does not actually validate the HTML, partial or broken tags can result in the removal of more text/data than expected.
Some Related Posts:-
- Add Content to the Thank You Page
- How to Remove the “Default Sorting” Dropdown
- Add Text Under Each Product on Shop Page
- Change Input Field to Textarea on Checkout
- Change Add to Cart Quantity into a Drop-down
- How to Merge My Account Tabs
This function does not modify any attributes on the tags that you allow using allowable_tags, including the style and onmouseover attributes that a mischievous user may abuse when posting text that will be shown to other users.
Additional checks have been implemented to prevent invalid tags from being removed where possible, by ensuring that the opening of each tag starts with a potential tag name; it does not account for greater than symbols within attributes. Comments will be retained but can be removed with a similar regex.
var no_comments = strip_tags('This is not a comment. ').replace(//, '');