html - Jquery: Traverse a table to find the occurance of a value and chage the row's css -
i have table structure as:
<table id="table1"> <thead> <tr> <th>task</th> <th>status</th> </tr> </thead> <tbody> <tr> <td>task 1</td> <td>suc</td> </tr> <tr> <td>task 2</td> <td>suc</td> </tr> <tr> <td>task 3</td> <td>err</td> </tr> <tr> <td>task 4</td> <td>err</td> </tr>
i want check status of task , if status err must change row's css. have jquery this:
$('#table1 td:nth-child(2)').each(function() { alert($(this).html()); if ($(this).html() == 'err') { $(this).css('background-color', '#ffe83d'); }
it changes css of particular cell of columun status .
i want change css of whole row status err. had tried things like
$(this).parent().css('background-color', '#59f763');
try : use closest('tr')
$('#table1 td:nth-child(2)').each(function() { alert($(this).html()); if ($(this).html() == 'err') { $(this).closest('tr').css('background-color', '#ffe83d'); } });
Comments
Post a Comment