jQuery DatePicker OnSelect Event Fired too early

2.6k views Asked by At
$("#div-calendar").datepicker({ onSelect: SelectedDay });

function SelectedDay(date, inst) {
    var s = inst.dpDiv.find('.ui-datepicker-current-day a').parent().attr("class");
    alert(s);

}

Im trying to get the class of the clicked date/cell.

The Problem is the Event happens BEFORE the class change, so it will always show me the classes of the previous click. I would need "OnSelected" instead.. any ideas?

1

There are 1 answers

2
Ken Browning On BEST ANSWER

An ugly hack I've resorted to using in the past:

$("#div-calendar").datepicker({ onSelect: SelectedDay });

function SelectedDay(date, inst) {
    // HACK: the ui hasn't been updated yet, check later
    window.setTimeout(function() {
        var s = inst.dpDiv.find('.ui-datepicker-current-day a').parent().attr("class");
        alert(s);
    }, 0);
}