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 8984151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:01:23+00:00 2026-06-15T21:01:23+00:00

I get returned from the server more than 50 items in my xml response.

  • 0

I get returned from the server more than 50 items in my xml response. I know it would be better to handle on the server but this is a request:

Make 2 lists with open <ul> and closing <\ul> each of them has 10 items from the response. No ordering just counting from beginning.

My loop now look like this:

var strHtml = '<ul>';
$(xml).find('Books row').each(function()
{
   strHtml += '<li><a href ="mylink">sometext</a></li>';
   // ...
});
strHtml += '<\ul>';
$('#category').empty().append(strHtml);

What i need is 2 lists, so i have to handle open and close UL tag in the loop.
Something like this, but i’m not sure if i’m doin it allright:

var itemCounter = 1,
    strHtml ='';

    $(xml).find('Books row').each(function()    //note: function( index )
    {
       if (itemCounter  == 1){
         // first iteration opens <ul>
         strHtml += '<ul>'; 
       }
       else if(itemCounter > 10){
         // 10th list item created. 
         // close first UL and open next UL
          strHtml += '</ul><ul>';
       }
       else if(itemCounter > 20){
         // max items allowed detected
         // close <ul> and break loop
         strHtml += '</ul>';
         return;
       }

       // regular li
       strHtml += '<li><a href ="mylink">sometext</a></li>';
       itemCounter++;

    });
    $('#category').empty().append(strHtml);

How would you handle this?

sidenote:

my html/css structure needs to have 2 vertical side by side lists. I found the best result to be in two and float them left, instead of having one list and floating every single item.

  • 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-06-15T21:01:24+00:00Added an answer on June 15, 2026 at 9:01 pm

    All that opening and closing and checking the counter stuff seems a bit fiddly, and also this line:

    else if(itemCounter > 10){
    

    will be true every time once the counter is above 10 so it’ll never go into the final else if block.

    I’d put all the li elements into a single array and then just .slice() out of the array and .join():

    var lis = [];
    $(xml).find('Books row').each(function(){
       lis.push('<li><a href ="mylink">sometext</a></li>');
       if (lis.length === 20)
          return false; // break out of .each()
    });
    
    var $cat = $("#category").empty();
    for (var i = 0; i < lis.length; i += 10)
        $cat.append('<ul>' + lis.slice(i,i+10).join("") + '</ul>');
    ​
    

    Demo: http://jsfiddle.net/nRtmj/1/

    Note that because I’ve done the .slice() and .join() in a loop you can easily create additional ul elements if you change the first loop so that it doesn’t stop at 20 elements: http://jsfiddle.net/nRtmj/2/ or if you want to change the number of elements per list just change the 10 to something else: http://jsfiddle.net/nRtmj/3/

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

Sidebar

Related Questions

I'm trying to get the returned value from a java method, but it returns
I want to get the information that is returned by this query from SolrNet:
Django's get_or_create function always cause get() returned more than one Model name error in
I have a JS function that processes XML I GET from a server to
How can I get the size in bytes of the data returned from the
Okay so I'm struggling more than I should with this. I've been to the
Good day, This is more web service design than programming question I think. I'll
Im using JQUERY + CodeIgniter. I can't seem to get the returned data to
We can get the type returned by function in gcc using the typeof operator
I am trying to get some errors returned in JSON format. So, I made

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.