As you can see, I am running a function for each of td of a specific table for finding text of the selected td. I have to change text inside that div so instead of coding more each function for change text inside div.
I coded this select inside of prev each function:
datevalue = $(this).parent().prev().find('div').find('div').find('span').text();
Is this a good way or not?
$('table > tbody > tr> td:last-child > span:last-child').each(function() {
ValidationInt = $(this).text();
datevalue = $(this).parent().prev().find('div').find('div').find('span').text();
console.log(datevalue);
ValidationInt = parseInt($(this).text());
console.log(ValidationInt);
if (ValidationInt <= 0) {
$(this).addClass('label-default');
$(this).prev().addClass('label-default');
} else if (0 < ValidationInt && ValidationInt <= 25) {
$(this).addClass('label-danger');
$(this).prev().addClass('label-danger');
} else if (25 < ValidationInt && ValidationInt <= 50) {
$(this).addClass('label-warning');
$(this).prev().addClass('label-warning');
} else if (50 < ValidationInt && ValidationInt <= 75) {
$(this).addClass('label-info');
$(this).prev().addClass('label-info');
} else {
$(this).addClass('label-success');
$(this).prev().addClass('label-success');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td>DiskTest</td>
<td>176</td>
<!-- <td><span class="label label-danger">Хийгдэж байна</span></td> -->
<td>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="">
10/06-10/31 <span>(-25)</span>
</div>
</div>
</td>
<td>
<span class='label'>in progress</span>
<span class='label'>0%</span>
</td>
</tr>
<tr>
<td>DiskTest</td>
<td>176</td>
<!-- <td><span class="label label-danger">Хийгдэж байна</span></td> -->
<td>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="">
10/06-10/31 <span>(-25)</span>
</div>
</div>
</td>
<td>
<span class='label'>progress</span>
<span class='label'>0%</span>
</td>
</tr>
<tr>
<td>DiskTest</td>
<td>176</td>
<!-- <td><span class="label label-danger">Хийгдэж байна</span></td> -->
<td>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="">
10/06-10/31 <span>(-25)</span>
</div>
</div>
</td>
<td>
<span class='label'>progress </span>
<span class='label'>0%</span>
</td>
</tr>
</tbody>
</table>