datepicker is not a function

This question is already asked many times but none of them worked for me. I am trying to use this date picker in a JSP file. This is my script

The shortcut file is loading perfectly, alert is also showing. I get error message as TypeError: $(. ).datepicker is not a function . I am not facing this problem if I run this script in a html file placed in my desktop, when I copy the come code to my IDE and run it I get this error in my console. Please suggest me what can I do? I know this question is asked several times I have checked every answer this is the only link having close match to my prob but didn’t work for me.

I’m trying to include the datepicker for Bootstrap but am getting the following error:

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

I don’t see why it’s there. I’ve looked at other cases of this error, but none match mine.

HTML:

JS:

UPDATE after adding JQuery UI

When i use DatePicker, jQuery’s UI plugin, in an existing .aspx page I get errors that:

However, when I copy and paste the same code that creates and uses the datePicker to an HTML file that’s also in the same directory as the aspx page, it works flawlessly. This leads me to assume that there are some JS files in the aspx page that’s preventing the datePicker or maybe jQuery’s UI JS files to load properly.

Can anyone confirm my beliefs or provide any tips on finding the culprit that’s interfering with jQuery’s UI plugins?

16 Answers 16

I struggled with a similar problem for hours. It then turned out that jQuery was included twice, once by the program that I was adding a jQuery function to and once by our in-house debugger.

If there is another library that is using the $ variable, you can do this:

Also make sure your javascript includes are in the correct order so the jquery core library is defined before the jquery.ui. I’ve had that cause issues.

This error usually appears when you’re missing a file from the jQuery UI set.

Double-check that you have all the files, the jQuery UI files as well as the CSS and images, and that they’re in the correctly linked file/directory location on your server.

jQuery “ $(”#datepicker“).datepicker is not a function”

I have fixed the issue by placing the below three files in the body section of the form at the end.

If you think that there is a conflict you can use jQuery.noConflict() in your code. Details are in the docs.

REFERENCING MAGIC — SHORTCUTS FOR JQUERY

If you don’t like typing the full «jQuery» all the time, there are some alternative shortcuts:

Reassign jQuery to another shortcut var $j = jQuery; (This might be the best approach if you wish to use different libraries) Use the following technique, which allows you to use $ inside of a block of code without permanently overwriting $:

Note: If you use this technique, you will not be able to use Prototype methods inside this capsuled function that expect $ to be Prototype’s $, so you’re making a choice to use only jQuery in that block. Use the argument to the DOM ready event:

Note: Again, inside that block you can’t use Prototype methods

Thats from the end of the docs and might be useful to you

Источник: computermaker.info

Понравилась статья? Поделиться с друзьями:
Ок! Компьютер
Добавить комментарий