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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:50:01+00:00 2026-06-18T11:50:01+00:00

Trying to hightlight table row using JQuery but not working, can anyone tell me

  • 0

Trying to hightlight table row using JQuery but not working, can anyone tell me why and how to fix it?

table:

<table id="customers">
    <caption>Customers</caption>
    <thead>
        <tr>
            <th>Customer no</th>
            <th>Last name</th>
            <th>First name</th>
            <th>Options</th>
        </tr>
    </thead>
    <tbody>
        <tr class="alt">
            <td>1</td>
            <td>Jackson</td>
            <td>Simon</td>
            <td>
                <div class="align-left">
                    <input type="submit" name="View" id="view" value="View" />
                </div>
                <div class="align-right">
                    <input type="submit" name="Rent" id="rent" value="Wants to rent" />
                </div>
            </td>
        </tr>
        <tr class="alt">
            <td>1</td>
            <td>Miller</td>
            <td>Darren</td>
            <td>
                <div class="align-left">
                    <input type="submit" name="View" id="view" value="View" />
                </div>
                <div class="align-right">
                    <input type="submit" name="Rent" id="rent" value="Wants to rent" />
                </div>
            </td>
        </tr>
    </tbody>
</table>

JQuery:

    $("#customers tbody tr").hover(

    function () {
        $(this).css({
            background: 'yellow'
        });
    },

    function () {
        $(this).css("background", "");
    });

What happens is the table row does not get highlighted when hovering over it, please also note that it works for a td when i adjust the selector, just wont work for tr row.

css:

    ...
    /* table data style */

    table {

        border-collapse: collapse;    
        width: 400px;
        color: grey;
        font-family: sans-serif;

    }

    th, td {

        border-bottom: 1px solid brown;
        padding: 5px;
        background-color: seashell;
        text-align: left;    

    }

    th {

        width: 200px;

    }

    td {

        width: 200px;

    }

    tr.alt td, tr.alt th {

        background-color: white;

    }

    tr:last-child td, tr:last-child th {

        border-bottom: 0;

    }

    caption {

        font-weight: bold;
        padding-bottom: 5px;

    }

    .main-font {

        font-family: sans-serif;

    }
  • 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-18T11:50:03+00:00Added an answer on June 18, 2026 at 11:50 am

    I’ll add to sbeliv01’s correct answer that there is no need for Javascript, it is realizable with pure CSS, and I would strongly advise you to use it for this sort of thing:

    #customers tbody tr:hover
    {
      background: yellow;
    }
    

    EDIT after OP post full CSS code:
    Yes, your CSS is “blocking” the hover effect, because you are applying background-color on your td elements. So your tr background color is correctly changed yellow, but you can’t see it as your tds are still seashell/white.

    To fix your problem, apply background color to trs in your CSS and not to your tds:

    table {
    
        border-collapse: collapse;
        width: 400px;
        color: grey;
        font-family: sans-serif;
    
    }
    
    th, td {
        /* Remove background-color here */
        border-bottom: 1px solid brown;
        padding: 5px;
        text-align: left;
    
    }
    
    /* Add this declaration (with the color previously applied to "th, td") */
    tr
    {
        background-color: seashell;
    }
    
    th {
    
        width: 200px;
    
    }
    
    td {
    
        width: 200px;
    
    }
    
    /* Change your selector from "tr.alt td, tr.alt th" to this */
    tr.alt {
    
        background-color: white;
    
    }
    
    tr:last-child td, tr:last-child th {
    
        border-bottom: 0;
    
    }
    
    caption {
    
        font-weight: bold;
        padding-bottom: 5px;
    
    }
    
    .main-font {
    
        font-family: sans-serif;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to highlight rows in a table using jQuery, but I'm wondering if
I am trying to highlight a table row using Jquery's .hover() method. I have
I'm trying to highlight just one specific row in a table using jQuery. The
I want to highlight a table row by changing its color, using jQuery. Have
I'm using jQuery 1.4. I'm trying to highlight the <td> tag of a Table
I'm trying to user JQuery to make a table row clickable and redirect to
I'm trying to have a simple html table, that highlights a row as a
I'm trying to highlight a row in my table when someone clicks on it.
I'm trying to highlight the table cell that is in row, col. var $tr
I have a table row which has class='highlightedrows' within my html I am trying

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.