String.prototype.stripTags goes through a string; removes tags and comments based on a regular expression (/<\/?[^>]+>/gi); and returns a copy of the string sans tags. Useful in many situations, such as where the text of a HTML string needs to be displayed as an alert.
string.stripTags();
A copy of string, sans tags.
<script type="text/javascript">
var stringTags = '<p><strong>This</strong> <em>is</em> ' +
'<!-- Comment --> <b>a</b> <i>paragraph</i>.</p>';
var stringNoTags = stringTags.stripTags();
// stringNoTags = 'This is a paragraph.';
stringNoTags = '<p>This <em>is</em> <b>a</b> <i>paragraph</i>.</p>'.stripTags();
// stringNoTags = 'This is a paragraph.';
</script>
stringNoTags is equal to ‘This is a paragraph.’.
stringTags remains equal to ’<p><strong>This</strong> <em>is</em> <!—Comment—> <b>a</b> <i>paragraph</i>.</p>’.
Because String.prototype.stripTags does not actually validate the HTML, partial and/or broken tags may result in stripping more than expected.