title: $(...).datepicker(...).data(...).selectDate is not a function
body: <p>I have function that works with datepickers</p>
  
  <p>Here it is </p>
  
  <pre><code>$(".multi_datepicker").each((key, elem) =&gt; {
    $(elem)
      .datepicker({
        language: gon.locale,
        minDate: new Date($(elem).attr("data-mindate")),
        maxDate: new Date($(elem).attr("data-maxdate")),
        autoClose: true,
        onShow: (inst, animationCompleted) =&gt; {
          if (animationCompleted) return true;
          var id = Number(inst.$el.attr("id").split("_")[2]);
          if (id &lt; 0) return true;
          var previous = $(`#search_legs_${id - 1}_date`);
          if (previous.length == 0) return true;
          var date = previous.datepicker().data("datepicker")
            .selectedDates[0];
          if (inst.selectedDates[0] &lt; date) inst.selectedDates = [date];
          inst.update("minDate", date);
        },
        onSelect: (dateText, inst) =&gt; {
          var no_count = Number($("#search_no_legs").val());
          var p = $("#search_legs_0_date").val();
          for (let i = 1; i &lt; no_count; i++) {
            var leg_id = `#search_legs_${i}_date`;
            if ($(leg_id).val() &lt; p) $(leg_id).val(p);
            p = $(leg_id).val();
          }
        }
      })
      .data("datepicker")
      .selectDate(new Date($(elem).attr("data-defaultDate")));
  });
  </code></pre>
  
  <p>}</p>
  
  <p>But last row cause error</p>
  
  <blockquote>
    <p>$(...).datepicker(...).data(...).selectDate is not a function</p>
  </blockquote>
  
  <p>I cannot unserstood why?</p>
  
  <p>How I can solve it?</p>