2012-01-26 44 views
2

我基本上试图克隆一个已经存在于页面上的div,两次。这是我想克隆什么:克隆一个div两次

<div class="tnt-zombies"> 
    //code in here 
</div> 

我还需要有一类增强的一个克隆股利和第二克隆一类溢价。我还想添加一个克隆到这两个克隆中的每一个的类,所以当我去除它们时,我可以调用克隆类。

,我想有最后的结果是这样的:

<div class="tnt-zombies">//other code in here</div> 
<div class="tnt-zombies cloned enhanced">//other code in here</div> 
<div class="tnt-zombies cloned premium">//other code in here</div> 

我希望是有道理的。

回答

3

尝试了这一点:

var the_clone = $('.tnt-zombies').clone().addClass('cloned'); 

var enhanced = the_clone.clone().addClass('enhanced'); 
var premium = the_clone.clone().addClass('premium'); 

$('body').append(enhanced, premium); 

小提琴:http://jsfiddle.net/maniator/Arzmm/

+0

得到它的工作。谢谢 – user1075615

+0

@ user1075615您的欢迎^ _ ^ – Neal

0

你也可以做到这一点在单次:

$('.tnt-zombies').clone().addClass('cloned enhanced').insertAfter('.tnt-zombies').end().clone().addClass('cloned premium').insertAfter('.tnt-zombies:last');