I am trying to dynamically change the background color of table cells based on their values. Here is an example of the code I have written:
applySchedules = function(schedules){
$.map(schedules, function(value, index){
$('#'+value.start).css('background', 'green');
});
}
var temp = [{start:9, end:10}, {start:13, end:14}]
applySchedules(temp);
tr {
border-width:2px;
outline:solid;
}
td {
border-width:2px;
width:60px;
outline:solid;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<table>
<tr>
<td id="8">8AM</td>
<td id="9">9AM</td>
<td id="10">10AM</td>
<td id="11">11AM</td>
<td id="12">12PM</td>
<td id="13">1PM</td>
<td id="14">2PM</td>
<td id="15">3PM</td>
<td id="16">4PM</td>
<td id="17">5PM</td>
<td id="18">6PM</td>
<td id="19">7PM</td>
<td id="20">8PM</td>
</tr>
</table>
Essentially, I receive a JSON array containing time slots that are reserved for a specific day. The challenge arises when a slot spans more or less than one hour because time slots are in increments of 30 minutes.
For example:
{start:10,end:11.30},{start:12,end:12.30},{start:14.30,end:15}
I am seeking advice on how to handle these types of scenarios.
Sample Output : https://i.sstatic.net/lku5Z.png