views:

227

answers:

1

So I have what I think is a pretty basic question but I cant for the life of me figure it out. How do you reference the selected date element (dom) once clicked. I have tried this:

$("#eventCalendar").datepicker({
 onSelect: function(dateText,inst){  
  var activeDateObj = $("#eventCalendar").find('.ui-state-active');  
 } 
});

This returns an object but I think it references the previously selected element; as in the class has not yet been applied to the new element. I'm really surprised the inst object doesn't contain some reference to the clicked element. I got this method to work by wrapping a quick timeout around the variable declaration but this is pretty dirty and I want to know if there is a better way. Thanks in advance.

+1  A: 

In Response to comments on OP.

From what I can tell the calendar seems to reload the table containing the days of the month each time a day is selected, it does this when you change months also.

If you use .live('click',function(){...}) this should allow you to attach your function.

For the selector something like this might be the best

 //attached to an input, not displayed inline.
$('#ui-datepicker-div .ui-datepicker table.ui-datepicker-calendar td[class!=ui-state-disabled]')

You now just have to work out which date was selected.

Nalum
Yea this is not a bad idea. not sure why i missed this lol.. But I'm wondering if its possible to accomplish the same thing with the "beforeShow" event or maybe "beforeShowDay" event?
Jabes88
beforeShowDay would allow you to show a tooltip which you could use to say something about the specific day but neither of those two events will allow you to set a function on the click event of the day, from what I understand.I'm not really sure what you want, but beforeShowDay might be enough for want you want.
Nalum
OK then that wont work. I have a custom build tooltip that needs to follow the cursor when you hover over specific dates. The method in this answer should do the trick, it just seems a bit crude to me. I wonder why they don't have some sort of build-in method for this.
Jabes88