Check if Bootprap Datepicker script is loaded

I get an error message:

Uncaught TypeError: undefined is not a function 

When I try to configure datepicker:

 $('.datepicker').datepicker(); 

How to determine if a date picker is loaded?

To be clear, I do not use jQuery UI

+7
javascript jquery html twitter-bootstrap bootstrap-datepicker
source share
2 answers

You can check if the date picker script has loaded using:

 if ($.fn.datepicker) { // ... } 

Then you can conditionally call the .datepicker() method if the script is loaded:

 if ($.fn.datepicker) { $('.datepicker').datepicker(); } 

Example here

However, an error will not be selected if the script is not loaded.


You can also use:

 if (typeof $().datepicker === 'function') { $('.datepicker').datepicker(); } 

Example here

+15
source share

This stopped loading bootstrap-datepicker more than once across all modules ..

 $.isFunction(Date.today) || $('body').append('<script src="assets/bootstrap-daterangepicker/date.js"><\/script><script src="assets/bootstrap-daterangepicker/daterangepicker.js"><\/script>'); 
-one
source share

All Articles