Site Loading

DatePicker with dynamic DOM Elements

I have been battling with a problem with the date picker. The problem is that when I add new inputs with the DatePicker class they do not behave in the same way as with the document load. The code I was using was:

$(document).ready(function (){
     $("input.datePicker").datepicker();
});

After that I was just trying to rebind the events using the destroy and datepicker methods.  Unfortunately this did not work!  Eventually I found this great stackoverflow answer and since I was cloning the elemtns I had to remove the hasDatePicker to rebind.

$('.date').last().removeClass('hasDatepicker');
$('.date').last().removeAttr('id');
$('.date').last().datepicker();

Hopefully this helps if you have the same problem.

Close