如何在单击“添加图片”按钮时将元素附加到最近的元素?
这是html结构:
<div class="step"
<div class="step-wrapper>
<div class="editor"></div>
</div>
<div class="delete-picture">
<div class="add-picture">
</div>
<div class="step"
<div class="step-wrapper>
<div class="editor"></div>
</div>
<div class="delete-picture">
<div class="add-picture">
</div>
<div class="step"
<div class="step-wrapper>
<div class="editor"></div>
</div>
<div class="delete-picture">
<div class="add-picture">
</div>
这是我错误的jQuery:
$(document).on('click', '.add-picture', function() {
var imageField = $('<img class="link" >');
$(this).parent().find(".step-wrapper").after(imageField);
});
点击 .step 后应如下所示:
<div class="step"
<div class="step-wrapper>
<img class="link" >
<div class="editor"></div>
</div>
<div class="delete-picture">
<div class="add-picture">
</div>