jQuery Highlight Element Based on Current Date Time

[javascript]
/**
* $.dateTimeHighlightNow()
* Adds/removes a selected class on elements based on the current date and time.
* usage: $(‘.program p’).dateTimeHighlightNow();
*/
jQuery.fn.dateTimeHighlightNow = function()
{
return this.each(function()
{
var datetimestamp = Math.round(new Date().getTime() / 1000)
elem = $(this),
start = elem.attr(‘start’),
finish= elem.attr(‘finish’);

log(‘datetimestamp = ‘+datetimestamp);

if (start < datetimestamp && finish > datetimestamp)
{
elem.addClass(‘selected’);
log(elem);
}
else
{
elem.removeClass(‘selected’);
}

});
};
[/javascript]

Leave a Reply