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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:17:39+00:00 2026-06-01T07:17:39+00:00

I have a hard-coded list, each list item of which has an ID. I

  • 0

I have a hard-coded list, each list item of which has an ID. I want to have jQuery generate list items in another list, and set as their text content the ID attribute values of each of the hard-coded list’s items:

i.e. hard-coded list:

<ul class="gallery"> 
    <li id="1"></li>
    <li id="2"></li>
    <li id="3"></li>
</ul> 

jQuery-generated list:

<ul class="galleryNav"> 
    <li>Slide 1</li>
    <li>Slide 2</li>
    <li>Slide 3</li>
</ul> 

I have jQ getting the number of gallery items …

var ListItemCount = $('ul.gallery').children().size('li');

… here’s the trouble: how do I get jQuery to get each of the list items’ IDs as it generates the nav list (below) ?

var ListItemIndex = $('ul.pofo li').attr('id');
var listItem = '<li>Slide #' + ListItemIndex + ' of ' + $('ul.gallery li').length + ' list items!</li>';

this is generating the nav list however the content in each is the same because of my blindspot with regard to var ListItemIndex

$("ul.gallery li").each(function (i) {
    i = i+1;
    $('ul.galleryNav').append(listItem);
});

The results of the above code generates the list but all the list items’ content is the same, ‘Slide #1 of 3 items’.

Many thanks in advance!

svs

  • 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-01T07:17:40+00:00Added an answer on June 1, 2026 at 7:17 am

    Here is the jsFiddle. The code:

    var listItemCount = $('.gallery').children().size('li');
    
    $('.gallery li').each(function() {
        $('.galleryNav').append(
            '<li>Slide #' + $(this).attr('id') + ' of ' 
                 + listItemCount + ' list items!</li>');
    });
    

    Your code had the basics right, you just need to move the appending to the each function that will execute for each list item. The item can then be accessed with $(this).

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

Sidebar

Related Questions

I have a C program which has always used hard coded define statements for
I have hard-coded data into a .jsp file. What I want to do is
I have an NSIS installer that has the start menu folders hard-coded using this
I currently have a site with a hard-coded list of categories & subcategories, where
I have currently hard-coded in some data for a demo of a project. The
I have a hard coded URL like so: https://bupacouk.bwa.local.internal.bupa.co.uk/cash-plan-quote/quoteAction.do?getBenefitLevelDetails=getBenefitLevelDetails&productPolicyId=7841#a1 When Javascript is enabled i
I have 4 hard coded divs. After the third div I would like to
I have a very hard-coded XML reader below: using System; using System.Collections.Generic; using System.Linq;
I have something like this hard-coded: private string[,] m_RolesForUser = new string[,] { {John,President,Chair},
I have a rather complex ListView, with variable list item heights. Under certain conditions,

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.