克隆除指定类的div之外的HTML页面

tom*_*cam 4 jquery

使用jQuery克隆HTML文件很容易:

alert($("html").clone().html());
Run Code Online (Sandbox Code Playgroud)

我的目标是克隆整个程序,除了'.ignore'类的div之外,但我能做的最好只显示那些div.

// 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());
Run Code Online (Sandbox Code Playgroud)

除了指定的div类之外,获得所有div类的最佳方法是什么?

Str*_*ner 7

你可以使用这个.end功能

alert($("html").clone().find('.ignore').remove().end().html());
Run Code Online (Sandbox Code Playgroud)

这里有一个工作小提琴:http://jsfiddle.net/sh99ognm/