I'm using bootstrap DatePciker , and I want to add a Click event on days (td), When I click on any day, add class to that 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
You need to use changeDate
event of datePicker.
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');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.