您好,欢迎访问一九零五行业门户网

jquery中append、prepend, before和after方法的区别

1.  append()和prepend()假设<p class='a'> //<---you want p c to append in this <p class='b'>b</p> </p>

使用
$('.a').append($('.c'));

效果如下:
<p class='a'> //<---you want p c to append in this <p class='b'>b</p> <p class='c'>c</p> </p>

同样使用
$('.a').prepend($('.c'));

效果如下:
<p class='a'> //<---you want p c to append in this <p class='c'>c</p> <p class='b'>b</p> </p>

2. 使用after()和before.html target=_blank>before()同样使用假设代码:
$('.a').after($('.c'));

效果如下:
<p class='a'> <p class='b'>b</p></p><p class='c'>c</p>

同样使用before()
$('.a').before($('.c'));

效果如下:
<p class='c'>c</p><p class='a'> <p class='b'>b</p></p>

总结:append() & prepend()是在元素内插入内容(该内容变成该元素的子元素或节点),after() & before()是在元素的外面插入内容(其内容变成元素的兄弟节点)。
1. append()和prepend()假设<p class='a'> //<---you want p c to append in this <p class='b'>b</p> </p>

使用
$('.a').append($('.c'));

效果如下:
<p class='a'> //<---you want p c to append in this <p class='b'>b</p> <p class='c'>c</p> </p>

同样使用
$('.a').prepend($('.c'));

效果如下:
<p class='a'> //<---you want p c to append in this <p class='c'>c</p> <p class='b'>b</p> </p>

2. 使用after()和before()同样使用假设代码:
$('.a').after($('.c'));

效果如下:
<p class='a'> <p class='b'>b</p></p><p class='c'>c</p>

同样使用before()
$('.a').before($('.c'));

效果如下:
<p class='c'>c</p><p class='a'> <p class='b'>b</p></p>

总结:append() & prepend()是在元素内插入内容(该内容变成该元素的子元素或节点),after() & before()是在元素的外面插入内容(其内容变成元素的兄弟节点)。以上就是jquery中append、prepend, before和after方法的区别的详细内容。
其它类似信息

推荐信息