我正在尝试克隆标题并将其附加到图像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和for each函数
$( ".current .project" ).each(function() {
var ptitle = $(this)
$("ptitle .projectitle").clone().appendTo($("ptitle .thumb"));
});
任何帮助都会很棒
答案 0 :(得分:1)
$(".current .project .projectitle").each(function() {
var $this = $(this), $target = $this.parent().next();
$this.clone().appendTo($target);
});