FullCalendar doesn't seem to do us any favors in terms of associating days or events with the DOM elements that represent them. No matter: we can do it ourselves.
Working example: http://jsfiddle.net/nNjFb/
var $calendar = $('#calendar');
$calendar.fullCalendar({
dayClick: function (date) {
// Create a string representing just the day/month/year of the date clicked
dateString = date.getDate() + date.getMonth() + date.getFullYear();
// Grab the events for that day using a custom filter function
events = $('#calendar').fullCalendar('clientEvents', function (event) {
eventDate = event.start;
eventDateString = eventDate.getDate() + eventDate.getMonth() + eventDate.getFullYear();
return dateString === eventDateString;
});
if (events.length) {
// Find the first event's element by its class name
var $event = $calendar.find('.' + events[0]._id);
$event.trigger('click');
}
},
eventClick: function (event) {
console.log('event click!', event);
},
eventRender: function(event, element) {
// Every time an event is rendered,
// add its id as a class name so that
// we can find it later
$(element).addClass(event._id);
}
});
// Add some events
var newEvent1 = {
title: 'first event',
start: new Date('October 31 2013 4:00 PM EST'),
allDay: false
};
var newEvent2 = {
title: 'second event',
start: new Date('October 31 2013 6:00 PM EST'),
allDay: false
};
$calendar.fullCalendar('renderEvent', newEvent1);
$calendar.fullCalendar('renderEvent', newEvent2);
There are two keys here:
Use the eventRender hook to attach a useful class name to the dom elements that are associated with events.
Use the clientEvents method and a custom filter to get an array of events that match the clicked day.