I know when you create an element dynamically, you have to use something like:
$(\"#id\").live(\"click\", function() {
//something
});
The accepted solution won't work with keyboard focus events.. so I had to change to this:
$('.parent').on('focusin', '.datepicker', function(e) {
$(this).datepicker(options);
});
Had to change .live
to .on
since jquery 1.9.1 doesn't include the .live
method. The above works for the mouse events as well as keyboard focus events.