Alan Schapira Alan Schapira - 8 days ago 4
C# Question

jQuery error in MVC project: Datepicker is not a function

This is what is in my view:

@Html.TextBox("toDateFilter", "", new { @class = "datepicker" })

<script src=""></script>
<script src=""></script>

$(document).ready(function () {

I am getting the error:

Datepicker is not a function.

I have followed the advice of all the other similar questions, and nothing has worked. I also changed the View to these imports instead:

<script type="text/javascript" src="//"></script>
<script src="//"></script>
<link rel="stylesheet" href="//" />

I also tried this instead:

var $j = jQuery.noConflict();

Also I did check that the jquery-ui.min.js file loaded correctly.

Any ideas why this is going wrong? Let me know if I can supply more info...


This is the answer from Starscream1984 in the comments, so props to them!

The issue is that the ready() function was being called before the jquery-ui.js script had finished loading.

This could not be fixed by moving it into the <head> nor loading the scripts from my own domain.

I was able to fix it simply by removing the ready() function entirely, and just running the contents.

If anyone knows how I can force the script to load first, or the ready() function to be called last, please let me know.