MyBB Community Forums

Full Version: jQuery .append() issue.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm in the process of writing some javascript pagination for a site that I'm working on. The idea of it is that once you get to the bottom, you click on "load more" and the additional content is loaded via AJAX and appended to the table displaying it.

Now, I have the PHP side of things working fine. The output is being collected properly and I can print it out with document.write().

However, I cannot manage to get it placed into the table. Below is the code that I have with previous attempts commented out but kept as a note.

			$.get("http://domain.com/updates/more/" + offset, function(data){
				//$(data).appendTo("table.posts");
				//$("table.posts").append(data);
				//$("table.posts tr:last").after(data);
				document.write(data);
			});
That is inside the callback function for the click.

I can provide the HTML if it is required but it is quite a big table so I thought it would be better to just see if I'm being stupid with the javascript.
I take it the table has the class "posts"? Are you intending to add new rows to the end of the table (before the close) or just add a new table to the end of the table?

Also, your .after() selector is incorrect. Try this:

$("table.posts tr:last-child").after(data);
(2011-07-24, 05:41 PM)euantor Wrote: [ -> ]I take it the table has the class "posts"? Are you intending to add new rows to the end of the table (before the close) or just add a new table to the end of the table?

Also, your .after() selector is incorrect. Try this:

$("table.posts tr:last-child").after(data);

The page returns more table rows which then need to be inserted into the table after the last tr already there and yes, it does have the .posts class.

Also, thanks for picking up on the after selector but, sadly, it didn't make any difference.

It's also tried with .html() to check if I had the right selector for the table which I did. However, no content was added. The only change was the old stuff being removed.
Strange. .html() should work if document.write() is returning the correct data.
This issue is now fixed thanks to the guys at forrst.com Smile
Glad to hear that! I can't believe I didn't think of the solution though haha