View Full Version : Jquery problems using append

11-29-2008, 08:35 PM
First off here's the code:

function getLastPost(id,reply){
var isReply = (reply != undefined) ? "&reply="+reply:"&reply=0";
type: "GET",
url: "./ajaxphp/getPosts.php",
data: "amount=1&ID="+id+isReply,
dataType: "html",
success: function(data){
if(reply != undefined){
if(!$("#post-"+id+" > ul").hasClass("postReply")){
$("#post-"+id).append("<ul class=\"postReply\"></ul>");

$(data).hide().prependTo("#post-"+id+" > ul.postReply");
$("#postMain").append("<ul class=\"postEntry\"></ul>");


So basically what this function is doing is getting an <li> of data and inserting it into a <ul>. However, if that ul isn't there it will append one. The "id" variable gets the id of the post and inserts it into ul.postEntry, however if the post is a reply to another it will create a ul.postReply within the parent post and put the <li> data into that. Everything in the "else" clause of the conditional works fine. It's just this line that will not work

if(!$("#post-"+id+" > ul").hasClass("postReply")){
$("#post-"+id).append("<ul class=\"postReply\"></ul>");

This conditional checks if there is a ul.postReply and if not make one. I checked it with an alert, and the conditional fires off properly however the append part never works which is weird because the other append works fine. What am I doing wrong?

03-12-2010, 07:03 PM
The only thing I can think is your element "#post-"+id doesn't exist..? Or is it appending the <ul> tag somewhere you're not expecting?

01-10-2011, 03:30 AM
Hi ,...
The append method expects a string or DOM node as argument. You are calling it with an object (json). The contents of this object will depend on the data sent by the server. What does the alert print on your screen? Using FireBug you can inspect the properties available to your json object: console.log(json).
I hope this information will helps a lot,..