0

I'm using this code to initialize a datepicker plugin on my input

$('.datepicker input').datepicker({
    ... (options)
});

This works fine if the input is already present on page load, but for dynamically added inputs this does not work.

I tried doing it this way instead which doesnt not work either.

$('body').datepicker({
    selector: '.datepicker input',
    ... (options)
});

Is there a way to accomplish this?

Richard Mišenčík
  • 324
  • 1
  • 8
  • 19
  • 1
    possible duplicate of [putting datepicker() on dynamically created elements - JQuery/JQueryUI](http://stackoverflow.com/questions/10433154/putting-datepicker-on-dynamically-created-elements-jquery-jqueryui) – George Jul 17 '15 at 15:28

1 Answers1

1

Found an answer here: putting datepicker() on dynamically created elements - JQuery/JQueryUI

$('body').on('focus', '.datepicker input', function() {
    $(this).datepicker({
        ...
    });
});​
Community
  • 1
  • 1
Richard Mišenčík
  • 324
  • 1
  • 8
  • 19