I've got a table, which function is to make the cell red or green, depending on the date of the cell.
Now when i set the datetest to 24-09-2017, all the cells go red, as expected in the code. When i change it to 26-07-2017, it changes to green, which is again, as expected. Now I want to make it so, that only 1 cell has a date in the past, and the rest in the future. How can i make my code so, that it does just that?
Here is my code:
var datetest = '22-9-2017';
alert("Welcome")
var d = new Date();
var month = d.getMonth() + 1;
var day = d.getDate();
var output = (day < 10 ? '0' : '') + day + '-' +
(day < 10 ? '0' : '') + month + '-' +
d.getFullYear();
$(document).ready(function() {
if (datetest < output) {
$('.test1').css("background-color", "red");
$('.test2').css("background-color", "red");
$('.test3').css("background-color", "red");
$('.test4').css("background-color", "red");
$('.test5').css("background-color", "red");
} else {
$('.test1').css("background-color", "green");
$('.test2').css("background-color", "green");
$('.test3').css("background-color", "green");
$('.test4').css("background-color", "green");
$('.test5').css("background-color", "green");
}
$('.test1').text(output);
$('.test2').text(output);
$('.test3').text(output);
$('.test4').text(output);
$('.test5').text(output);
});
td {
padding: 20px;
}
<!DOCTYPE HTML>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
</head>
<table>
<tr>
<th>werkvoorbereiding</th>
<th>Ordervrijgave productie</th>
<th>Buigen</th>
<th>Zagen</th>
<th>Metaal</th>
</tr>
<tr>
<td class="test1">1</td>
<td class="test2">2</td>
<td class="test3">3</td>
<td class="test4">4</td>
<td class="test5">5</td>
</tr>
</table>
</html>