2013-03-12 24 views
1

我想克隆標題並將其附加到圖像div。這裏是哪裏的標題應該去註釋標記:移動標題並追加到下一個圖像

<div class="current"> 
<div class="project"> 
    <div class="col"> 
     <a class="projectitle" href="#">Title1</a> 
    </div> 

    <div class="thumb"> 
     <img src="image1.jpg"> 
     <!-- Clone title1 and move here --> 
    </div> 

</div> 

<div class="project"> 
    <div class="col"> 
     <a class="projectitle" href="#">Title2</a> 
    </div> 

    <div class="thumb"> 
     <img src="image2.jpg"> 
     <!-- Clone title2 and move here --> 
    </div> 

</div> 

這工作,但將所有的標題,並將它們附加到所有的div

$(".current .project .projectitle").each(function() { 
$(this).clone().appendTo($(".thumb")); 
}); 

一點也不正確但我試圖使用jQuery和每個功能

$(".current .project").each(function() { 
var ptitle = $(this) 
$("ptitle .projectitle").clone().appendTo($("ptitle .thumb")); 
}); 

任何幫助將大

回答

1
$(".current .project .projectitle").each(function() { 
    var $this = $(this), $target = $this.parent().next(); 
    $this.clone().appendTo($target); 
}); 

http://jsfiddle.net/C42T8/

+0

感謝堆,非常有意義。 – uriah 2013-03-12 01:50:46

相關問題