1. append()和prepend()
假设
//<---you want p c to append in this
b
使用
$('.a').append($('.c'));效果如下:
//<---you want p c to append in this
b
c
同样使用
$('.a').prepend($('.c'));效果如下:
//<---you want p c to append in this
c
b
2. 使用after()和before()
同样使用假设代码:
$('.a').after($('.c'));效果如下:
b
c
同样使用before()
$('.a').before($('.c'));效果如下:
c
b
总结:
append() & prepend()是在元素内插入内容(该内容变成该元素的子元素或节点),after() & before()是在元素的外面插入内容(其内容变成元素的兄弟节点)。
1. append()和prepend()
假设
//<---you want p c to append in this
b
使用
$('.a').append($('.c'));效果如下:
//<---you want p c to append in this
b
c
同样使用
$('.a').prepend($('.c'));效果如下:
//<---you want p c to append in this
c
b
2. 使用after()和before()
同样使用假设代码:
$('.a').after($('.c'));效果如下:
b
c
同样使用before()
$('.a').before($('.c'));效果如下:
c
b










