Jquery Remove html tags from html string

I need to load an html string into memory from a page and remove divs that have a specific class using jQuery.

What I'm trying to do is below, but it does not work.

var reportHTML = $('#collapsereportsdata').html()
$(reportHTML).(".dontprintme").each().remove();

thank

+3
source share
1 answer

To get HTML with tags removed, you can .clone()element and delete elements that you do not want before receiving it., Like this:

var newHTML = $('#collapsereportsdata').clone().find(".dontprintme")
                                               .remove().end().html();

Performs the .clone()original element, does .find()to get the elements you want .remove(), then uses .end()to return to the cloned element, since the one you want to get html through .html()from.

+9
source

All Articles