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(da开发者_运维技巧teText,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.
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.
Solution
//...
onSelect: function(date, inst) {
setTimeout(function() {
console.log($('a.ui-state-active')); // clicked day's DOM-Element
}, 0);
}
The setTimeout-Wrapper will queue the stuff after the calendar got refreshed.
精彩评论