tags:

views:

49

answers:

1

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

What I am trying to do is below but it doesn't work.

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

Thanks

+2  A: 

To get the HTML with the tags removed you can .clone() the element and remove the elements you don't want before getting it's HTML, like this:

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

This performs a .clone() of the original element, does a .find() to get the elements you want to .remove(), then uses .end() to jump back to the cloned element, since that's the one you'd want to get the html via .html() from.

Nick Craver
works great thanks
Jamie