我希望如果某个身体在课堂上添加div" post-image"。它将在div之前自动将它移动到类" post-header"并使用class single-post在每个div上执行此功能。
E.g. this is main //'post-image' after 'post-header'
<div class='single-post'>
<div class='post-header'>Title</div>
<div class='post-image'><img src='.../img1.png'/></div>
</div>
<div class='single-post'>
<div class='post-header'>Title</div>
<div class='post-image'><img src='.../img2.png'/></div>
</div>
and i want this like this // 'post-image' before 'post-header'
<div class='single-post'>
<div class='post-image'><img src='.../img1.png'/></div>
<div class='post-header'>Title</div>
</div>
<div class='single-post'>
<div class='post-image'><img src='.../img2.png'/></div>
<div class='post-header'>Title</div>
</div>
答案 0 :(得分:0)
也许是这样的:
$(".post-header").each(function (ind, el) {
$(this).siblings(".post-image").each(function (ind, el2) {
$(el).before($(el2));
});
})