3

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

1
  • 1
    does it work without the each() ? Commented Aug 3, 2010 at 23:33

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.