I have multiple jquery datetimepickers on a page. Trying to set the date on ‘Today’ button click but the following sets for all of the datetimepickers on the page?
How do I set only the one that has focus (using Trent Richarsons jquery datetimepicker)?
$.datepicker._gotoToday = function (id) {
var inst = this._getInst($(id)[0]),
$dp = inst.dpDiv;
this._base_gotoToday(id);
var tp_inst = this._get(inst, 'timepicker');
now = new Date();
var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
this._setTime(inst, now_utc);
$('.datetime').datepicker('setDate', now_utc); // <- this woks but sets date for all datetimepickers! how to I set for current focus datetimepicker
};
Use the
:focuspseudo-selector, like this:Alternatively you could also give each datepicker an specific id so you can select by it: