I'm working on a dynamic calendar that allows user to click on individual days to change whether they're available or unavailable. It works as it's supposed to up until I select another month or year. Once that happens the "click" event on individual cells/days doesn't work.
// Changes cell background of the calendar
var changeColor = function(temp) {
// if cell background is white -> change to green
if(temp.css('background-color') == "rgba(0, 0, 0, 0)") {
temp.css('background-color', 'green');
// if cell background is green -> change to red
} else if (temp.css('background-color') == "rgb(0, 128, 0)") {
temp.css('background-color', 'red');
} else {
// else change back to white
temp.css('background-color', '');
}
};
Here is were it's used
$(document).ready(function() {
// When a date-cell is clicked - changes color to green -> red -> white
$(".calCell:not(.empty)").click(function() {
changeColor($(this));
});
});
The two buttons that change the whole calendar to red or green seem to work fine with each month selected.
// When Available button is click -> changes whole calendar to available
$("#yes").on("click", function() {
$(".calCell:not(.empty)").css('background-color', 'green');
});
// When Unavailable button is clicked -> changes whole calendar to unavailable
$("#no").on("click", function() {
$(".calCell:not(.empty)").css('background-color', 'red');
});
Example: JS Fiddle