Frank Tian Frank Tian - 1 year ago 110
jQuery Question

What's the difference between bootstrap datepicker "setDate" and "update" methd?

I've tried to use

$element.datepicker('setDate', dateObj);


$element.datepicker('update', dateObj);

to set the internal date of a datepicker. But it looks like if i use setDate, the default selected date(which is the start date) is still highlighted, but update will clear the default selected date and use the new dateObj as selected

I wonder how to clear the default selected date with setDate

Answer Source

I've been playing around trying out different alternatives to the API and according to my findings, there's no difference between those two.

$("#calendar").datetimepicker("update",new Date());
$("#calendar").datetimepicker("setDate",new Date());

It seemed to me confusing and suspicious that they'd put in two different methods for the same task so I started asking around. By the word of mouth, I've learned that the former was originally intended to be the general setter of all properties but due to technical issues, the functionality was dropped (only retaining the date setting capability due to compatibility issues for pre-existing code).

$("#calendar").datetimepicker("update", "weekStart", 4);

The above was but isn't anymore changing the starting week of the control.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download