2012-01-26 51 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');