jQuery UI - Draggable is not a function?
I've trying to use the draggable effect on some divs on a page, but whenever I load the page, I get the error message:
Error: $(".draggable").draggable is not a function
I've had a look around it seemed other people were having this problem as they had not included the jQuery UI javascript file, but I definitely have.
The following is within the head tag of my page:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
Can anyone suggest a solution?
Any advice appreciated.
Thanks.
Quick edit, I also have the jquery tools js included in the head of the page, if I remove this it works OK. Has anyone managed to get these two working together?
Solution 1:
A common reason occurs is if you don't also load jqueryui after loading jquery.
For example:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js" type="text/javascript"></script>
EDIT. Replace the version number for each library with appropriate or latest values for jquery and jqueryui.
If this doesn't solve the issue, review suggestions in the many other answers.
Solution 2:
4 years after the question got posted, but maybe it will help others who run into this problem. The answer has been posted elsewhere on StackExchange as well, but I lost the link and it's hard to find.
ANSWER: In jQueryTOOLS, the jQuery 'core' is also embedded if you use the default download.
When you load jQuery and jQuery tools, jQuery core gets defined twice and will 'unset' any plugins. 'Draggable' (from jQuery-UI) is such a plug-in.
The solution is to use jQuery tools WITHOUT the jQuery 'core' files and everything will work fine.
Solution 3:
-
Install jquery-ui-dist
use npm
npm install --save jquery-ui-dist
or yarn
yarn add jquery-ui-dist
-
Import it inside your app code
import 'jquery-ui-dist/jquery-ui';
or
require('jquery-ui-dist/jquery-ui');
Solution 4:
Make sure your code follows this order-
<script src="jquery.min.js"></script>
<script src="jquery-ui/jquery-ui.js"></script>