lundi 7 novembre 2016

JQuery: Change the color of the row inside a table based on the checkbox click

I have a table that has huge set of data. Now what i want to do is when user will uncheck the checkbox of that specific row, i want to change the color to grey. What i have done till now:

$('tr').click(function () {
    if(this.style.background == "" || this.style.background =="white") {
        $(this).css('background', 'grey');
    }
    else {
        $(this).css('background', 'white');
    }   
});

$(".uncheck").change(function(){
    alert("cehc");
    var ischecked= $(this).is(':checked');
    alert(ischecked);
    if(!ischecked){
        $(this).css('background', 'grey');
    }
    else{
        $(this).css('background', 'white');
    }
});

The above functions i have written that work properly individually though. Its like The first function will work when i click on row and second function puts an alert on unchecking the checkbox but does not change the color to grey.

How to identify if a specific checkbox has been unchecked on a row of a table and change that row color to grey?




Aucun commentaire:

Enregistrer un commentaire