santa
santa

Reputation: 12512

Highlight row with jQuery on checkbox select

I have a table with multiple rows. Each row has a check button. How do i highlight the row (apply style I suppose) when the checkbox is selected?

Upvotes: 3

Views: 4532

Answers (3)

omabena
omabena

Reputation: 3581

$(function(){
    $(":checkbox").click(function(){

       var thischeck = $(this);
       var approved = (thischeck.is(':checked')) ? '1' : '0';
       if(approved) {
           //apply what ever you want
       }
    });
})(jQuery);

I would try this, not sure if it is an elegant solution.

Upvotes: 0

Alan
Alan

Reputation: 652

$(":checkbox:checked").each( 
function() 
{ 
    if (this.checked) 
    {
        this.addclass("yourClass");
    }
}

Upvotes: 0

karim79
karim79

Reputation: 342775

$(":checkbox").change(function() {
    $(this).closest("tr").toggleClass("highlight", this.checked);
});

See toggleClass() and closest()

Upvotes: 10

Related Questions