Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone an HTML page except divs of a specified class

Tags:

jquery

It's easy to clone your HTML file with jQuery:

alert($("html").clone().html());

My goal is to clone the whole program except divs of class '.ignore' but the best I can do is display ONLY those divs.

// This displays the inverse of what I want: just the code to be removed
alert($("html").clone().find('.ignore').remove().html());

// Seems to have the exact same effect as above:
alert($("html").clone().find('.ignore').html());

What's the best way to obtain all but the specified div class?

like image 333
tomcam Avatar asked Aug 30 '14 14:08

tomcam


1 Answers

You could use the .end function

alert($("html").clone().find('.ignore').remove().end().html());

A working fiddle is here: http://jsfiddle.net/sh99ognm/

like image 179
Stryner Avatar answered Nov 15 '22 04:11

Stryner