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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:11:33+00:00 2026-06-13T22:11:33+00:00

I have a loop: for (index = 0; index < total_groups; index += 1)

  • 0

I have a loop:

for (index = 0; index < total_groups; index += 1) {

    groups[index].list_item = $(list_item_snippet);

    // Closure to bind the index for event handling
    (function (new_index) {

        groups[index].list_item.find('.listing-group-title')
                               .html(groups[index].Group.Name)
                               .click(function(e){

            fns.manageActiveGroup(new_index, groups);
            return false;
        });

    })(index);

    // Append to DOM
    mkp.$group_listing.append(groups[index].list_item);
};

I would rather not call append() each time the loop fires.

I know that I could use a String and concatenate the markup with each loop iteration and append the string to mkp.$group_listing at the end, however this flattens the object and the bindings are lost (I am not relying on IDs).

Is there a way to perhaps add my objects to an array and append them all in one go at the bottom without flatening to HTML?

Assumptions:

  • $(list_item_snippet) contains some HTML defining a list item (and includes an element with class .listing-group-title).
  • groups is a block of JSON defining a ‘group’ in my script
  • The closure works perfectly

Edit:

Found that I can use the following syntax to append multiple elements:

mkp.$group_listing.append(groups[0].list_item, groups[1].list_item );

But i obviously need to automate it – it’s not an array it’s just optional additional function parameters so I’m not sure how to do this.

  • 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-13T22:11:34+00:00Added an answer on June 13, 2026 at 10:11 pm

    To append an array of elements to a selector you can use this:

    $.fn.append.apply($sel, myArray);
    

    In your case, since it’s actually the .list_item property of each array element that you need you can use $.map to extract those first:

    $.fn.append.apply(mkp.$group_listing, $.map(groups, function(value) {
         return value.list_item;
    }));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a loop $(.box).find('.video, .print, .web').closest('.box').each(function (index) { $(this).delay(100 * index).fadeIn(300); }); This
I have an mutable array, allRows . In a loop, I assign each index
If I bind a function to flot's plotselected event, is there a way to
I have loop designed to validate the user input on a question, it was
I have loop for: for (int i = 1; i < 2000; i++) How
I have loop and each iteration of Hash looks like this: [1, {:clid=>1, :nvz=>4,
I'm pretty new to jQuery/JS. But I have loop in jQuery where I would
I have this loop method to display a ViewPager and I set an OnClickListener
I have a loop that enters each non-empty text field into a database: foreach
I have a loop in razor which generates a template a number of times.

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.