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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:41:19+00:00 2026-06-07T02:41:19+00:00

I have 4 checkboxes, each in a separate <div> . Each div has a

  • 0

I have 4 checkboxes, each in a separate <div>. Each div has a corresponding class (widthCol1 -> widthCol4).
Each div is inside a separate <td> in a single <tr> of a <table>.
Depending on what combination of checkboxes are selected, I need to color the row of the table in a specific color.

Considering only the first 2 checkboxes it should color the row #ffaaaa when .widthCol2 input is checked and #ccff99 when it is not. Also it should color the row #fff if there is no checkbox selected (not implemented).

The script doesn’t work if there is a second checkbox selected in other row. Why ?

$(".widthCol1 input").click(function () {
    if ($(this).is(":checked")) {
        if ($(".widthCol2 input").is(":checked")) {
            $(this).closest("tr").css("background-color", "#ffaaaa");
        } else {
            $(this).closest("tr").css("background-color", "#ccff99");
        }
    } else {
        // test other checkboxes before coloring #fff
    }
});

This script will have to be used for all 4. Is there also a better, cleaner way to test them ?

  • 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-07T02:41:20+00:00Added an answer on June 7, 2026 at 2:41 am

    This is the solution.
    The script below (partial copy of mine) will retrieve every row in the table and then, will find the 3 checkboxes that I need. After that it will test them and assign to color the correct color code. In the end it will assign the color to the row. In this way I only need to concern myself with 3 variables and not all the checkboxes (with their specific index) that are in the table.

    $("input[type=checkbox]").click(function () {
        var vals = $(this).closest("tr");
        vals.each(function () {
            var color = "#fff";
            var c1 = $(this).find(".widthCol1 input:checkbox");
            var c2 = $(this).find(".widthCol2 input:checkbox");
            var c3 = $(this).find(".widthCol3 input:checkbox");
            if ($(c2).is(":checked")) {
                color = "#ffaaaa";
            } else {
                $(c1).is(":checked") ? color = "#ccff99" : color = "#fff";
            }
            $(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 a large number of checkboxes on the page each in a separate
I have many checkboxes in a dynamically produced (ASP) photo gallery. Each checkbox has
I'm trying to setup custom validation for a checkbox. I have 7 checkboxes each
I have three sets of checkboxes (serviceA, B & C) with 5 checkboxes each,
I have a page with several CheckBoxList controls with 4 checkboxes in each of
I have a ListView with multiple checkboxes (one for each list item). What would
I have a page with many checkboxes, each of which are tied to a
I have a table with checkbox and a dropdown in each row. I'd like
If I have 7 checkBoxes, one for each day of the week, Can I
I have several tabs. Each tab has several nested elements that contain checkbox input

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.