jqueryjquery-uidatepickerinstanceonselect

jquery ui datepicker onselect inst target


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.


Solution

  • 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.