Skip to content Skip to sidebar Skip to footer

Js/jquery Typeerror: Jquery(...).datepicker Is Not A Function

I've been scratching my head on this for 2 days, pretty sure I'm just missing something simple but I can't for the life of me figure out why it's not working. I'm trying to use the

Solution 1:

The are several reasons for this error:

  1. The jquery.ui is used before jquery.
  2. The $ is used by another library.
  3. The jquery lib that is referenced locally(wordpress) has different version from that using jquery.ui.
  4. When the right library and version is referenced the browser cache must be cleared.

Solution 2:

I was having the same problem. In my case I had two jQuery script references on my main page (_Layout.cshtml in ASP.NET MVC). I added 1 reference to jQuery at the top but there was 1 at the bottom of the page that I didn't notice... In Firebug this is what I saw:

enter image description here

So as you can see, jQuery UI was sitting in the middle of the conflict! :D This took me some time to figure out.

Solution 3:

check if all files are loaded.Should have 200 ok status.

Solution 4:

This worked for me, for conflicting jquery codes -

<script>  
  $.noConflict();  //Not to conflict with other scriptsjQuery(document).ready(function($) {
$( "#datepicker" ).datepicker({
  dateFormat:"yyyy-mm-dd",
  changeMonth: true,
  changeYear: true,
  maxDate: "+0D"
});

});
</script>

Solution 5:

I know this question is old but may be It can help other people:

The best practice to include js in wordpress is to do it using It's queuing function in the php template:

wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array ( 'jquery' ), 1.1, true);

(seen here)

It allows to declare the dependencies of your script, in this case, the jquery datepicker. You can check de built-in scripts that wordpress can provide in:

https://developer.wordpress.org/themes/basics/including-css-javascript/#default-scripts-included-and-registered-by-wordpress

Wordpress provide dependencies specifically for jquery datepicker so you could include your script with something like:

wp_enqueue_script( 'script', 'mypath' . '/js/script.js', array ( 'jquery', 'jquery-ui-datepicker' ), 1.7, true);

Note that if you only declare the jquery dependency you'll get an error like

'jQuery.datepicker(...) is not a function'

since the datepicker functions are not included in the base wordpres jquery.

Post a Comment for "Js/jquery Typeerror: Jquery(...).datepicker Is Not A Function"