title: How to bind jQuery Datepicker after Ajax refresh?
body: <p>I've got a jQuery datepicker that is working great for me, except when I fresh the content via ajax, I lose the datepicker. From what I can tell I should be using jQuery <code>on()</code> to bind it to the input, but I can't seem to find the right event to bind it to.</p>
  <p>Works the first time, but not on subsequent refreshes:</p>
  <pre><code>$(&quot;[id^=startPicker]&quot;).datetimepicker({
          showOn: &quot;button&quot;,
          buttonImage: &quot;/img/calendar_icon.png&quot;,
          buttonImageOnly: true,
          dateFormat: 'mm/dd/yy',
          timeFormat: 'hh:mm tt',
          stepMinute: 1,
          onClose: function (dateText, inst) {
  
              var selectedDate = $(this).datepicker(&quot;getDate&quot;); //Date object
  
              $.ajax({
                  url: &quot;/url&quot;,
                  dataType: &quot;json&quot;,
                  method: 'post',
                  data: {
                      value: selectedDate.toDateString() + ' ' + selectedDate.toTimeString()
                  },
                  beforeSend: function () {
                      $(&quot;#loading&quot;).fadeIn();
                  },
                  success: function (data, textStatus) {
                      $(&quot;#content&quot;).html(data);
                  },
                  complete: function () {
                      $(&quot;#loading&quot;).fadeOut();
                  }
              });
          }
      });
  </code></pre>
  <p>Doesn't bind first time or on subsequent refreshes:</p>
  <pre><code>$('#content').on('ready', &quot;[id^=startPicker]&quot;, function () {
          $(this).datetimepicker({
              showOn: &quot;button&quot;,
              buttonImage: &quot;/img/calendar_icon.png&quot;,
              buttonImageOnly: true,
              dateFormat: 'mm/dd/yy',
              timeFormat: 'hh:mm tt',
              stepMinute: 1,
              onClose: function (dateText, inst) {
      
                  var selectedDate = $(this).datepicker(&quot;getDate&quot;); //Date object
      
                  $.ajax({
                      url: &quot;/url&quot;,
                      dataType: &quot;json&quot;,
                      method: 'post',
                      data: {
                          value: selectedDate.toDateString() + ' ' + selectedDate.toTimeString()
                      },
                      beforeSend: function () {
                          $(&quot;#loading&quot;).fadeIn();
                      },
                      success: function (data, textStatus) {
                          $(&quot;#content&quot;).html(data);
                      },
                      complete: function () {
                          $(&quot;#loading&quot;).fadeOut();
                      }
                  });
              }
          });
      });
  </code></pre>