Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1063105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:44:04+00:00 2026-05-16T18:44:04+00:00

Hey guys, I have a bit of a weird problem. I have a jquery

  • 0

Hey guys, I have a bit of a weird problem. I have a jquery script that basically prepends messages from data in a php script in descending chronological order one by one so that latest messages are on the top. What I want to do is somehow put a div container around two or more these messages as they come out so I decided to check which message is oldest and prepend that message with a tag and the newest message with the tag since each message comes out one by one. This however has not worked because the div does not seem to detect the enclosure and only partially encloses the 2 test messages (only the first one is enclosed). If anyone has any recommendations on how to accomplish this I would love to hear them.

     function prepare(response) {
          count++;

//function in another doc
nicetime = handleDate(response.timestamp);

if (response.replydiv=='start'){
    var list_name='<div id="chunk">start';
}
else{
    var list_name='';
}
  if (response.creator!==''){
        var list_name=list_name+'<li class="message-list-creator" id="list-'+count+'">'
    }
    else{
        var list_name=list_name+'<li class="message-list" id="list-'+count+'">'
    }




            var string = ''+list_name+''

              + '<span class="message-list-nick"><a href="statistics.php?user='+response.user+'">'+response.user+'</a></span>'
              + ' <span class="date" id='+response.timestamp+'>'+nicetime+'</span><br>'
              + '<span class="msg">'+response.message+'</span>'
              + '<span class="clear"></span>'
              if(response.reply!='null'){
               var string = string +'<a message_id="'+response.reply_chunk_id+'" id="reply">reply</a></li>';
              }
              else {
                 var string=string+'</li>';
              }


              if (response.replydiv=='end'){
            var string=string +'</div>end';
        }

          return string;
        }

$.getJSON(files+"message.php?action=view&load=initial&topic_id="+topic_id+"&username="+username+"&t=" + (new Date()), function(json) {  
            if(json.length) {
              for(i=0; i < json.length; i++) {
                  json.sort(function(a,b) { return parseFloat(a.timestamp) - parseFloat(b.timestamp) } );
                $('#message-list').prepend(prepare(json[i]));
                $('#list-' + count).fadeIn(1500);
              }

            }

          });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:44:05+00:00Added an answer on May 16, 2026 at 6:44 pm

    You have a stray (and unmatched) </li> in there probably throwing your markup off, at this part:

    +'</li>';
    

    Also when you call .prepend() with the first unclosed <div> you’ll have issues…it’s not just adding HTML it’s making DOM elements, so you need to get your entire HTML string together then .prepend() it at once.

    You can optimize this much further, but the basic fixed version would be something like this:

    function prepare(response) {
      count++;
      //function in another doc
      var nicetime = handleDate(response.timestamp), string="";
    
      if (response.div=='start'){
        string = '<div id="chunk">start div';
      }
    
      string += list_name;
      string += '<span class="message-list-nick">'+response.message+'</span>';
    
      if (response.div=='end'){
       string += '</div>end div';
      }
      return string;
    }
    

    And the ajax call:

    $.getJSON(files+"script.php?action=view&load=initial&topic_id="+topic_id+"&username="+username+"&t=" + (new Date()), function(json) { 
      var output = "";
      for(i=0; i < json.length; i++) {
        json.sort(function(a,b) { return parseFloat(a.timestamp) - parseFloat(b.timestamp) } );
    
         output += prepare(json[i]);
         $('#list-' + count).fadeIn(1500);
      }
      $('#messagelist').prepend(output);
    });
    

    The important difference here is that we’re not appending to the DOM until the string’s complete…jQuery will complete the elements immediately (or attempt to) when calling .prepend() the first time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I have an ajax jquery function that receives data from a php
Hey guys, I have a bit of a problem that I can't solve. I'm
Hey guys, I have a bit of a problem. I get values from textarea
Hey guys am having a bit of problems with my jQuery, I have all
Hey guys I have one more question lol. I am using a script that
Hey guys, I have this quick bit of code that I can't figure out
Hey guys I have a query that selects data and organizes but not in
Hey guys i have a problem. I have a listview that is dynamically filled.
Hey guys I have my script here that is supposed to do some stuff
Hey guys I have an admin page that checks if you are admin before

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.