Unicorn
Unicorn

Reputation: 109

Button to select all check boxes and change entire table's bg color

this is what i have so far: - a table with 20 to 30 cells - each cell has 1 check box and a value (different value of course) - two button to trigger select all and select none checkboxes.

Codes so far: - to trigger select all/none:

Javascript:

function set_checked(checked) {
    $('input[name=test]').attr('checked', checked);
}

buttons:

onclick="set_checked(true)" and onclick="set_checked(false)" for both buttons.

now, how do i add color change on both buttons? for example, entire table bg color change to green when select all and change to white when select none.

Upvotes: 0

Views: 168

Answers (3)

Starx
Starx

Reputation: 79031

This should do, what is needed

function set_checked(checked) {
    $('input:checked').attr('checked', checked); //select all checkbox
    if(checked) {
         $("table").css("backgroundColor", "#ddd"); //new color
    } else {
         $("table").css("backgroundColor", "#fff"); //old color
    }
}

Upvotes: 1

Elias Zamaria
Elias Zamaria

Reputation: 101143

Maybe something like this:

onclick="set_checked(true); $('table').css('background', 'green')"
onclick="set_checked(false); $('table').css('background', 'white')"

Upvotes: 0

James Montagne
James Montagne

Reputation: 78710

You can use .css to change background color:

$("tableSelector").css("background-color","blue");

Upvotes: 1

Related Questions