Here's a slightly simpler solution that worked for me:
$(".fc-state-highlight").removeClass("fc-state-highlight");
$(jsEvent.currentTarget).addClass("fc-state-highlight");
...that goes inside of your click handler, like:
$('#eventCalendar').fullCalendar({
dayClick: function(date, allDay, jsEvent, view) {
$(".fc-state-highlight").removeClass("fc-state-highlight");
$(jsEvent.currentTarget).addClass("fc-state-highlight");
}
});
Note that this is using the dayClick
handler instead of the eventClick
handler. I don't see why it should not work with eventClick
as well, but I have not tested that yet.
Edit:
Using a comparable approach for the eventClick
handler proved to be more complicated than I thought it would be. The problem is that, in terms of DOM hierarchy, there is no parent/child relationship between the containing td
element for a 'day' and the containing div
elements for the events that are shows as occurring on that day.
So I had to write a function to lookup the correct td
element for a given date. I ended up with something like:
function findContainerForDate(date) {
var firstDayFound = false;
var lastDayFound = false;
var calDate = $('#eventCalendar').fullCalendar('getDate');
var allDates = $('td[class*="fc-day"]')
for (var index = 0; index < allDates.length; index++) {
var container = allDates[index];
var month = calDate.getMonth();
var dayNumber = $(container).find(".fc-day-number").html();
if (dayNumber == 1 && ! firstDayFound) {
firstDayFound = true;
}
else if (dayNumber == 1) {
lastDayFound = true;
}
if (! firstDayFound) {
month--;
}
if (lastDayFound) {
month++;
}
if (month == date.getMonth() && dayNumber == date.getDate()) {
return container;
}
}
}
...and then I could implement eventClick
like this:
eventClick: function(calEvent, jsEvent, view) {
var selectedContainer = findContainerForDate(calEvent.start);
$(".fc-state-highlight").removeClass("fc-state-highlight");
$(selectedContainer).addClass("fc-state-highlight");
}