Jump to content

Append to li:first-child


V

Recommended Posts

So I finally finished a comment system but it seems when everything looks perfect another issue arises :(

 

When you post a new comment, it loads it via Ajax without loading the page. And the newest comment appear first on top to li:first. All comments are wrapped in ul.

 

This is part of the code that does that

 

 

.....

$.ajax({
type: "POST",
url: "insert_comment.php",
data: dataString,
cache: false,
success: function(html){
$("ul.comments li:first").before(html);
$("ul.comments li:empty").append(html);
}
});
}return false;

....

 

The issue is, the very first comment in the post doesn't appear unless you refresh. It does however when I remove the li:first and li:empty and for example just use $("ul.statuses").append(html); but then the comment won't appear on top as I want to.

 

The comments following the first appear like I want to.. I just can;t figure out why the first does that

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.