I need to get from ‘page’+i a container div with id = ‘posts1’, but I’m struggling to add a .getElementById or similar to this function:
$.get('page-'+i, function(data){
content = data;
$('#posts').append(content);
});
I’ve tried adding it on content, data and putting ‘page’+i in brackets and then adding .getElementById but nothing works, i’m always getting that what i’m doing isn’t a function or error 500 (Internal Server Error).
Edit:
This is the full function:
function showMore() {
if (i<=196) {
$.get('page-'+i+' #posts' , function(data){
content = data;
$('#posts').append(content);
});
i++;
}
This is activated on a click of a button.
I need to append, after the existing articles in #posts, more articles that are for ex in page-2 in the div with id ‘posts1’.
2
Answers
I've found where was my issue:
I've added
.find
to my data and it's working perfectly.You can use template literals and .load
If
i
is 1, then this will read a page with filenamepage-1
and insert the element from that page with id="post1" into the element with id="posts" on current pageAdded to a simpler version of your function