The selected answer does not always guarantee that the HTML will be deleted, since you can still build an invalid HTML string through it by creating a string as shown below.
"<<h1>h1>foo<<//</h1>h1/>"
This entry ensures that the description collects a set of tags for you and will result in:
"<h1>foo</h1>"
Additionally, the jquery text function will skip text not surrounded by tags.
Here's a function using jQuery, but should be more robust in both cases:
var stripHTML = function(s) { var lastString; do { s = $('<div>').html(lastString = s).text(); } while(lastString !== s) return s; };
Rick Moynihan Apr 04 '13 at 15:31 2013-04-04 15:31
source share