in addition to Andrew Whitaker solution there is another way to do it (actually its a hack but actually its maybe perfect for someone else because maybe the title or date is not always a good identifier)
Note: please read Andrew Whitaker solution first and see the changes here
// date picker
$("div").datepicker({
// hook handler
beforeShowDay: function(tdate) {
var mydata = $(this).data("mydata");
var enabled = false;
var classes = "";
var title = date;
$.each(mydata, function() {
if (this.date.valueOf() === tdate.valueOf()){
enabled = true;
classes = "highlight";
title = title + '" data-id ="'+this.id;// my hack to add additional attributes ;)
}
});
return [enabled,classes,title];
},
// event handler
onSelect: function() {
var id = $(this).find(".ui-datepicker-current-day").attr("data-id");
mydata = $(this).data("mydata"),
selectedData = null;
/* search for data id */
$.each(mydata,function(){
if (this.id == id){
selectedData = this;
}
});
if (selectedData) {
/* If the event is defined, perform some action here; show a tooltip, navigate to a URL, etc. */
alert(selectedData);
}
}
}).data("mydata",
// your data
[{
id:1,
title: "Five K for charity",
date: new Date("02/13/2011")
},
{
id:2,
title: "Dinner",
date: new Date("02/25/2011")
},
{
id:3,
title: "Meeting with manager",
date: new Date("03/01/2011")
}]);