jquery Remove html tags from html string
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 = $('#collapsereportsd开发者_如何学Pythonata').html()
$(reportHTML).(".dontprintme").each().remove();
Thanks
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.
精彩评论