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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:08:18+00:00 2026-05-14T18:08:18+00:00

I need that when i check a checkbox i apply different background color to

  • 0

I need that when i check a checkbox i apply different background color to HTML table rows according to and ID of a user in database using jquery, and then i uncheck the checkbox go to previous state.
For the record i am not asking for code i am asking for concept.

http://www.freeimagehosting.net/image.php?ef44cf44a5.jpg

  • 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-14T18:08:19+00:00Added an answer on May 14, 2026 at 6:08 pm

    You want to use a selector that matches the table rows, get the id of the user from the row and choose the color, then use the css function to set the background-color. You can use the data method to store the previous color. When your checkbox is unchecked, simply get the previous color using data, and restore it.

    If the id of the user isn’t included in the row or relatable to the row somehow, then you’ll need to change the table and add it, otherwise it isn’t possible.

    Here’s a little code to get you started — this is the “check” part.

    $('tr').each( function() {
        var id == $(this)...  // get user id
        var color = chooseColor( id ); // figure out color somehow
        $(this).data( 'previous-color', $(this).css('background-color') );
        $(this).css( 'background-color', color );
    });
    

    EDIT: Based on your comment, I think CSS classes may be a better solution for you — just assign the group name as the class. Then in your CSS have different CSS selectors for .groupX and .groupX.active, .groupY and .groupY.active, etc. Then all you need to do is add/remove the active class from the rows on checkbox toggle. I don’t know if the “active” class name is the most semantically appropriate, but it’s convenient for the example.

    CSS
    
    tr.group-ANIM { /* no special formatting */ }
    tr.group-ANIM.active { background-color: #f00; }
    
    tr.group-ZZZ { }
    tr.group-ZZZ.active { background-color: #0f0; }
    
    $('#toggleBox').click{ function() {
         var checked = $(this).filter(':checked').length > 0;
         if (checked) {
             $('tr').addClass('active');
         }
         else {
             $('tr').removeClass('active');
         }
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a checkbox when user checked that check box means. I need to
I need help with a script that when I check a checkbox it generates
I need to check that a string takes on the format 05:31:2008:06:27:2010 I do
I have two checkboxes. I need to check that at least one of them
Suppose that I check-in a change in the wrong TFS branch. I need to
I am programming a Java app in which i need to constantly check that
i need a javascript function that able to check for digit and - only.
I have class grades that I need to check if a specific grade is
I need to check if my address has any words that matches word in
I need an simple way to check whether a string that is sent to

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.