JavaScript
Article
By Sam Deering

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, '');
--ADVERTISEMENT--

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(//igm,'')
Recommended
Sponsors
The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account