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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:08:24+00:00 2026-06-06T06:08:24+00:00

I have the below table. I am trying to get tbody column bgcolors matching

  • 0

I have the below table. I am trying to get tbody column bgcolors matching with theader bg colors.

Can you please help , as I am not able to achieve this?

Thanks and Regards,

<table id="one" border="1">  <thead>  <tr>
 <th style="background-color:Lime">Header 1</th>
 <th>Header 2</th>  </tr>  </thead>  <tbody>  <tr>
 <td>row 1, cell 1</td>
 <td>row 1, cell 2</td>  </tr>  <tr>
 <td>row 2, cell 1</td>
 <td>row 2, cell 2</td>  </tr>  </tbody>  </table>   
 <script language="javascript" type="text/javascript">
     $(document).ready(function () {

         $('#one thead tr th').each(function () {

             var col1 = $(this).css("background-color");
             var index = $(this).closest("th").prevAll("th").length;

             assigncolr(col1, index);
         });
     });

    function assigncolr(col,index){   $('#one tbody tr').each(function () {
    $(this).find('td :nth-child(' + index + ')').css("background-color", col);


        }
          )
              };

 </script>
  • 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-06T06:08:26+00:00Added an answer on June 6, 2026 at 6:08 am

    A little bit shorter and simpler – http://jsfiddle.net/9X4FP/1/

    var cols = $("th").length;
    
    $("tbody td").each(function() {
        var order = $("td").index(this) % cols;
        var color = $("th:eq(" + order + ")").css("background-color");
    
        $(this).css("background-color", color);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below column on my table what gets binded on pageload, the
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have trying to get around making my first C# application(that can do more
Consider I have a table, like below, that I am trying to populate with
I'm trying to get parameters from the menu table in Joomla. What I have
I have the following code below and I'm trying to get an AVG for
I'm trying to get the sum of a column. My Schema is as below...
I have a table like below: Table A ---------- ID Field1 Field2 Field3 1
i have the table below <tr id=group_1>...</tr> <tr id=el>...</tr> <tr id=el>...<tr> <tr id=group_2></tr> <tr
I have a Generic List object which hold below table as its own value.

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.