Reputation:
I have the following code:
$('.content').load('http://example.com/page/2/ .content .post');
It gets all the content from that page, and replaces whatever was in $('.content')
, with the new stuff.
However, I don't want it to replace it, I want it to append to it.
I've tried:
$('.content').append($('.content').load('http://example.com/page/2/ .content .post'));
But it still replaces the content, it does not add to it.
Do you have any suggestions?
Upvotes: 1
Views: 38
Reputation: 337560
As you've seen load()
overwrites any content already in the element. If you want to append to existing content you need to roll your own AJAX request and use append()
:
$.get('http://example.com/page/2', function(html) {
$('.content').append($('.content .post', html));
});
Upvotes: 4