Is there an easy way to take a string of html in JavaScript and strip out the html?
As an extension to the jQuery method, if your string might not contain HTML (eg if you are trying to remove HTML from a form field)
jQuery(html).text();
will return an empty string if there is no HTML
Use:
jQuery('' + html + '
').text();
instead.
Update:
As has been pointed out in the comments, in some circumstances this solution will execute javascript contained within html
if the value of html
could be influenced by an attacker, use a different solution.