var date_id = 1;
this.addCity = function (){
$('#add').before('<input type="text" class="date initial hasDatepicker" id="date'+date_id+'" value="01/30/2012"></br>');
$("#date"+date_id).live('click', function(){
alert("#date"+date_id); //this alert works norm
$("#date"+date_id).datepicker();
});
}
The datepicker does not work, but I’m seeing no errors in the Firebug console.
Move your
.datePicker()call to outside the click handler, i.e.This is because, the
.datePicker()function is used to initialize the datePicker for a particular input element and not for rendering the datePicker immeidiately. Once initialized it will handle the click automatically.