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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:31:44+00:00 2026-05-26T09:31:44+00:00

The following code is just a demonstration for the theory that I want to

  • 0

The following code is just a demonstration for the theory that I want to apply to my app so using THIS instead of td.flex is not appropriate for the the second line in the function.

Also I MUST Use .index instead of nth-child for other reasons.

That all said 🙂

The following function loops through all the TD’s in the first row of a table that have a class of flex. For each of these record the index value. The next line is not part of the real application but to test the theory should find all the tds with a class of flex that have an index value that matches the cellIndex value. Any ideas how to get this to work?

Remember this code is to test the theory hence why I am not using nth-child or this to apply the css colouring!

cellIndex = new Array();

    $('table tr:first-child td.flex').each(function (i) {

        cellIndex[i] = $(this).index();

        $($('td.flex').index(cellIndex)).css('background-color', '#ff0000');

    });

if I do: console.log($('td.flex').index(cellIndex));

I get -1 for each loop

Just to confirm I know I could do this:

$(this).css('background-color', '#ff0000');

but this IS NOT what I’m trying to achieve with this function and would NOT work in the real application.

HTML example:

<table>
<tr>
<td class="flex">Flex</td>
<td>Not Flex</td>
<td class="flex">Flex</td>
<td>Not Flex</td>
<td>Not Flex</td>
</tr>
</table>
  • 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-26T09:31:45+00:00Added an answer on May 26, 2026 at 9:31 am

    the each function already include an index system. So you can use it like this (cellIndex is obsolete then): http://jsfiddle.net/TMFg3/

    cellIndex = new Array();
    
    $('table tr:first-child td.flex').each(function (i) {
    
        cellIndex[i] = i;
    
       $('td.flex:eq('+i+')').css('background-color', '#ff0000');
    
    });
    

    If you wan’t to use the cellIndex, then you have to loop it outside the each function, since you can’t post an array to an index identifer, plus it would change the same targets in each loop 🙂

    You can ofcourse also use the index in cellIndex like this:

    cellIndex = new Array();
    
    $('table tr:first-child td.flex').each(function (i) {
    
        cellIndex[i] = i;
    
       $('td.flex:eq('+cellIndex[i]+')').css('background-color', '#ff0000');
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to just make a single UILabel on my cell.
The following Java code just parses a date (with time portion) 2009-01-28-09:11:12 using SimpleDateFormat
In magento1.7, just write following lines in app\code\core\Mage\Wishlist\Helper\Data.php (Data.php) file public function getpdf() {
I'm using the following code just to convert any URL to starts with http://
I have the following code (just as a test) and I want to create
Im using the following code just for learning how to use the FIleService API,
I want to use the following code just to check the input. #include <stdio.h>
I am trying to obtain an element width using the following code just before
JQuery Mobile showPageLoadingMsg will not work in my application. The following code just produces
The following code works just fine: #include <exception> using namespace std; class FileException :

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.