You can set global datepicker options and then just apply the datepicker to particular fields with those settings:
- $(function() {
- $.datepicker.setDefaults({dateFormat: 'yy-mm-dd'});
- function addnew() {
- ...
- $('<input type="text" class="datepicker">').appendTo(mydiv).datepicker();
- }
- });
Also note that IDs must be unique within the document. Your current implementation of
addnew will create multiple text fields with the same ID.