I've got a table full of events, and I'm trying to get the number of events which are on at each hour. So that it is easy to see the number of concurrent events.
To do this, I'm running through the table looking for the event divs (which sit inside td), and then get the start and duration, and put that into a seperate div, adding them up as I go so I'll end up with '9:00, 5 events', 10:00, 3 events...
So far, I think the code is looking pretty good, but I've got a strange issue. I'm passing in a index so I know which cell is being counted. The first alert returns the index number. However, the second alert returns [object HTMLDivELEMENT], and I don't know why this is. I think everything would work fine if I could get the index after the .each function.
The code is this (simplified a bit for easier understanding)
for(sched=1;sched<8;sched++){
alert(sched);
jQuery('div.event', 'table#events td:nth-child('+sched+')').each(function(sched){
var start=jQuery(this).data('start');
var duration=jQuery(this).data('dur');
var eventId=jQuery(this).attr('id');
alert(sched);
for(t=0;t<=duration;t++){
var thisHour=start+t;
var numEvents=jQuery('li#hour'+thisHour, 'table#events td.dailyTotals:nth-child('+sched+')').data('count');
if(numEvents==null){
numEvents=0;
}
numEventsf++;
jQuery('li#hour'+thisHour, 'table#events td.dailyTotals:nth-child('+sched+')').css('background-color','red');
jQuery('li#hour'+thisHour,'table#events td.dailyTotals:nth-child('+sched+')').data('count', numEvents);
jQuery('li#hour'+thisHour,'table#events td.dailyTotals:nth-child('+sched+')').text(numEvents);
}
});
}