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

  • Home
  • SEARCH
  • 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 7404581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:16:30+00:00 2026-05-29T05:16:30+00:00

I am currently creating list on the fly with jQuery. The solution below is

  • 0

I am currently creating list on the fly with jQuery. The solution below is somewhat hacky I know, so I am wondering if its possible to stick it in a loop, so I can iterate through each div and create the list. Thanks for your help!!

         var text0 = $('#d0').text(); 
         var textArr0 = text0.split('*');

         var text1 = $('#d1').text(); 
         var textArr1 = text1.split('*');

         var text2 = $('#d2').text(); 
         var textArr2 = text2.split('*');

         $("#d0").html('<ul></ul>');
         $("#d1").html('<ul></ul>');
         $("#d2").html('<ul></ul>');


         $.each(textArr0, function (k, v) {
            $("#d0 ul").append('<li>' + '<a>' + v + '</a>' +  '</li>');
         });

         $.each(textArr1, function (k, v) {
            $("#d1 ul").append('<li>' + '<a>' + v + '</a>' +  '</li>');
         });

         $.each(textArr2, function (k, v) {
            $("#d2 ul").append('<li>' + '<a>' + v + '</a>' +  '</li>');
         });
  • 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-29T05:16:31+00:00Added an answer on May 29, 2026 at 5:16 am

    This is a tidied version of what you’ve already got…

    $(function() {
        $("#d0, #d1, #d2").each(function() {
            var text = $(this).text();
            var textArr = text.split("*");
            $(this).html("<ul></ul>");
            for(var i = 0; i < textArr.length; i++) {
                $(this).find("ul").append('<li><a>' + textArr[i] + '</a></li>');
            };
        });
    });
    

    But, I’d recommend giving the elements d0/d1/d2 etc. a class and use $(".className") to identify them so you can have as many or as few as you like without having to change that code.

    Here’s a demo… http://jsfiddle.net/77vM9/

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

Sidebar

Related Questions

I'm currently creating a circular doubly-linked list as exercise. The exercise is templating the
I am currently using the below code to get a list of uuid's then
I am currently creating a backend. What I need is some jquery to insert
I'm creating a website(PHP + MySQL based) with a list events. I currently have
I am creating a list item on the fly using the object notation (
I'm currently creating an explicit reference to this in the outer class so that
I'm currently creating an application for a customer that will allow them to automatically
I'm currently creating a WinForm in VB.NET bound to an access database. Basically what
I am currently creating an e-commerce site using C# ASP.NET MVC and have just
We are currently creating an InfoPath 2007 form is deployed in SharePoint 2007. In

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.