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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:46:09+00:00 2026-05-23T10:46:09+00:00

I’ve been trying to add classes to elements in my page depending on which

  • 0

I’ve been trying to add classes to elements in my page depending on which array they are, but I can’t find the problem in my code. I’m trying to find ‘.b001’ and add that element class ‘ct01’. The same for ‘.b005, .b002’ and add class ‘ct02’ and so on.
PadDigits adds the specified num of 0 before a number.

Thanks!!

function PadDigits(n, totalDigits) { 
    n = n.toString(); 
    var pd = ''; 
    if (totalDigits > n.length) 
    { 
        for (i=0; i < (totalDigits-n.length); i++) 
        { 
            pd += '0'; 
        } 
    } 
    return pd + n.toString(); 
}

var filatrans = new Array();
filatrans[0] =  '1';
filatrans[1] =  '5 2';
filatrans[2] =  '9 6 3';
filatrans[3] =  '12 10 7 4';
filatrans[4] =  '15 13 11';
filatrans[5] =  '26 21 18 16 14';
filatrans[6] =  '33 27 22 19 17';
filatrans[7] =  '40 34 28 23 20';
filatrans[8] =  '47 41 35 29 24';
filatrans[9] =  '54 48 42 36 30 25';
filatrans[10] = '61 55 49 43 37 31';
filatrans[11] = '68 62 56 50 44 38 32';
filatrans[12] = '75 69 63 57 51 45 39';
filatrans[13] = '82 76 70 64 58 52 46';
filatrans[14] = '89 83 77 71 65 59 53';
filatrans[15] = '96 90 84 78 72 66 60';
filatrans[16] = '103 97 91 85 79 73 67';
filatrans[17] = '110 104 98 92 86 80 74';
filatrans[18] = '117 111 105 99 93 87 81';
filatrans[19] = '124 118 112 106 100 94 88';
filatrans[20] = '125 119 113 107 101 95';
filatrans[21] = '126 120 114 108 102';
filatrans[22] = '127 121 115 109';
filatrans[23] = '128 122 116';
filatrans[24] = '129 123';
filatrans[25] = '130';

var w = filatrans;
for (e=0; e<w.length; e++) {
    fila = w[e].split(' ');
    var out;
    for (e=0; e<fila.length; e++) {
        out += '.b' + PadDigits(fila[e], 3) + ', ';
    }
    $(out).addClass('ct' + PadDigits(e+1, 2));
}
  • 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-23T10:46:10+00:00Added an answer on May 23, 2026 at 10:46 am

    The problem with the code is of course that you are using the same variable for the nested loops, as others already have mentioned.

    Despite your title, you are not using multidimentional arrays, you are just using an array of strings, where you create a new array from each string on the fly. You can use the array literal syntax to simplify creation of the array, and also create it with actual arrays instead of strings. That way you don’t have to create the arrays in the loop.

    I also made a simplified padDigits function.

    function padDigits(n, totalDigits) { 
      n = n.toString(); 
      while (n.length < totalDigits) n = '0'+n;
      return n;
    }
    
    var filatrans = [
      [1],
      [5, 2],
      [9, 6, 3],
      [12, 10, 7, 4],
      [15, 13, 11],
      [26, 21, 18, 16, 14],
      [33, 27, 22, 19, 17],
      [40, 34, 28, 23, 20],
      [47, 41, 35, 29, 24],
      [54, 48, 42, 36, 30, 25],
      [61, 55, 49, 43, 37, 31],
      [68, 62, 56, 50, 44, 38, 32],
      [75, 69, 63, 57, 51, 45, 39],
      [82, 76, 70, 64, 58, 52, 46],
      [89, 83, 77, 71, 65, 59, 53],
      [96, 90, 84, 78, 72, 66, 60],
      [103, 97, 91, 85, 79, 73, 67],
      [110, 104, 98, 92, 86, 80, 74],
      [117, 111, 105, 99, 93, 87, 81],
      [124, 118, 112, 106, 100, 94, 88],
      [125, 119, 113, 107, 101, 95],
      [126, 120, 114, 108, 102],
      [127, 121, 115, 109],
      [128, 122, 116],
      [129, 123],
      [130]
    ];
    
    var w = filatrans;
    for (var e = 0; e < w.length; e++) {
        var out;
        for (var f = 0; f < w[e].length; f++) {
            out += '.b' + padDigits(w[e][f], 3) + ', ';
        }
        $(out).addClass('ct' + PadDigits(e+1, 2));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

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.