Click trigger on bootstrap datepicker jQuery addClass not working

I am using bootstrap DatePciker and I want to add the Click event on days (td). When I click on any day, add a class to this day (td). but it does not work.

$('#calendar').datepicker({
    multidate: true,
    todayHighlight: true,
    todayBtn: true
});

$('tbody').on('click','td.day',function(e){
    e.preventDefault();
    $(this).addClass('clicked');
});

working example on jsfiddle

+4
source share
1 answer

You need to use the changeDatedatePicker event .

Docs: http://bootstrap-datepicker.readthedocs.org/en/latest/events.html

$('#calendar').datepicker('setDates', events)
    .on('changeDate', function (e) {
        // $(this).addClass('clicked'); // $(this) here is not what you think.
        $('.active').addClass('clicked');
    });

Demo: http://jsfiddle.net/2L1ovhbm/13/

+3
source

All Articles