jQuery getScript to load external script and call function that relies on script not working

213 views Asked by At

I have the following code to load an external script, I can see in the console network tab the script gets loaded but I get error:

Uncaught TypeError: $(...).pikaday is not a function

This is my script:

<input class="my-datepicker" id="from_date" type="text" placeholder="From" name="from_date" value="">

<script>

$(window).on('load', function() {

   $.when(
      $.getScript( "https://cdnjs.cloudflare.com/ajax/libs/pikaday/1.8.0/pikaday.min.js" ),
      $.Deferred(function( deferred ){
          $( deferred.resolve );
      })
   ).done(function(){

      $(".my-datepicker").pikaday({
         firstDay: 1
      });

  })

});

</script>
0

There are 0 answers