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,'')
Tags: jquery remove all html tags except, jquery take all text only from div, remove specific html tags
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.

Special Offer
Free course!

Git into it! Bonus course Introduction to Git is yours when you take up a free 14 day SitePoint Premium trial.