从.load()追加内容

时间:2014-04-17 12:38:10

标签: javascript jquery

我有以下代码:

$('.content').load('http://example.com/page/2/ .content .post');

它从该页面获取所有内容,并使用新内容替换$('.content')中的

但是,我不希望它替换它,我希望它追加

我试过了:

$('.content').append($('.content').load('http://example.com/page/2/ .content .post'));

但它仍然会替换内容,但不会添加内容。

你有什么建议吗?

1 个答案:

答案 0 :(得分:4)

您已经看到load()会覆盖元素中已有的任何内容。如果要附加到现有内容,则需要滚动自己的AJAX请求并使用append()

$.get('http://example.com/page/2', function(html) {
    $('.content').append($('.content .post', html));
});