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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:51:06+00:00 2026-05-21T06:51:06+00:00

I have successfully put highlighting in my table but the problem is with alternating

  • 0

I have successfully put highlighting in my table but the problem is with alternating the row color. The row color is alternating only after the row is highlighted. In
other words, when the page is first loaded or refreshed, all the row color is colored white which is the default. I want to fix this in a way that whether its first time loading the page or it is refreshed the color is already alternating. By the way, I used a combo of JavaScrpt, and embedded ruby for this.

Here is the code fragment for my index.html.erb:

<table id="table_list">
 <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='<%= cycle :odd, :even %>'">
  <td> Data 1 </td>
  <td> Data 2 </td>
 </tr>
</table>

and on my CSS:

<pre>
#table_list{
  border: solid 1px #666;
  border-collapse: collapse;
  margin: 10px 0;
}

#table_list th{
  font-size: 12px;
  color: #FFF;
  background-color: #404C99;
  padding: 4px 8px;
  padding-bottom: 4px;
  text-align: left;
}

#table_list .highlight {
    background-color: yellow;
}

#table_list td {
  font-size: 12px;
  padding: 2px 6px;
}

#table_list .even td {
  background-color: #E3E6FF;
}

#table_list .odd td {
  background-color: #D1D8F6;
}

</pre>
  • 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-21T06:51:07+00:00Added an answer on May 21, 2026 at 6:51 am

    Here you can use JQuery for this coloring purpose.

    You might find the :even and :odd selectors useful.

    You could then use them like this (Working Copy):

    Your can download jquery from jquery.com

        <style>
            #table_list .even td
            {
                background-color: #E3E6FF;
            }
            #table_list .odd td
            {
                background-color: #D1D8F6;
            }
            #table_list td.hover
            {
                background-color: green !important;
            }
        </style>
    
        <script language="javascript">
    
            $(document).ready(function() {
    
                $('#table_list').find('tr>td').hover(function() {
                    //$(this).css("background-color", "green");
                    $(this).addClass('hover');
                }, function() {
                    //$(this).css("background-color", "inherit");
                    $(this).removeClass('hover');
                });
                $('#table_list  tr:even').addClass('even');
                $('#table_list tr:odd').addClass('odd');
    
            });
    
    
    
        </script>
    
        <body>
            <form id="form2">
            <div>
                <table id="table_list">
                    <tr>
                        <td>
                            1
                        </td>
                        <td>
                            Babu
                        </td>
                    </tr>
                    <tr>
                        <td>
                            2
                        </td>
                        <td>
                            Satheesh
                        </td>
                    </tr>
                    <tr>
                        <td>
                            3
                        </td>
                        <td>
                            Ramesh
                        </td>
                    </tr>
                    <tr>
                        <td>
                            4
                        </td>
                        <td>
                            Venki
                        </td>
                    </tr>
                    <tr>
                        <td>
                            5
                        </td>
                        <td>
                            Abhishek
                        </td>
                    </tr>
                </table>
            </div>
            </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using Hibernate very successfully, but today I noticed a bizarre phenomenon
I have successfully put together 3three Histograms into 1one Plot with the Lattice package.
I have successfully connected to an Oracle database (10g) from C# (Visual Studio 2008)
I have a Rails app that I have successfully tested with Mongrel and Webkit.
I believe that I have successfully impersonated my own user account while running an
I'm familiar with the LAMP stack and over the years have successfully deployed a
using the Code Snippet for sending email in VB.Net I have successfully sent an
I'm just learning Qt with C++. I have successfully implemented signals and slots to
How can I set a parameter of a sub-report? I have successfully hooked myself
What I have now (which successfully loads the plug-in) is this: Assembly myDLL =

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.