1. append()和prepend()
假设
<div class='a'> //<---you want div c to append in this
<div class='b'>b</div>
</div>
使用
$('.a').append($('.c'));
效果如下:
<div class='a'> //<---you want div c to append in this
<div class='b'>b</div>
<div class='c'>c</div>
</div>
同样使用
$('.a').prepend($('.c'));
效果如下:
<div class='a'> //<---you want div c to append in this
<div class='c'>c</div>
<div class='b'>b</div>
</div>
2. 使用after()和before()
同样使用假设代码:
$('.a').after($('.c'));
效果如下:
<div class='a'>
<div class='b'>b</div>
</div>
<div class='c'>c</div>
同样使用before()
$('.a').before($('.c'));
效果如下:
<div class='c'>c</div>
<div class='a'>
<div class='b'>b</div>
</div>