JavaScript
Article

jQuery Strip All HTML Tags From a Div

By Sam Deering

Simple jQuery code snippet to strip all html tags from a div (ie keep only the text from inside the html tags) using the jQuery replace() function. Also see Remove whitespace.

var item_html = $(this).html();
item_html = item_html.replace(/< /?[^>]+>/gi, '');

Probably easier to use this function

jQuery.fn.stripTags = function () {
    return this.replaceWith(this.html().replace(/< /?[^>]+>/gi, ''));
};

jquery remove all html tags except:

rawHTML = textContainer.html().replace(/< /?[br|li|ol|ul]+/?>/igm,'')

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.