views:

48

answers:

1

It is really weird that the draggable works in all browsers but Firefox. I tried in IE6.0, Opera, Safari, all are ok. But Firefox prompted below error:

$("#draggable").draggable is not a function.

Here is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery UI Draggable - Default functionality</title>
<link rel="stylesheet" href="/js/ui/1.8.5/themes/base/jquery.ui.all.css"/>
<script type="text/javascript" src="/js/ui/1.8/js/jquery-1.4.2.min.js"></script>
<script type="text/jscript" src="/js/ui/1.8/ui/jquery.ui.core.js"></script>
<script type="text/jscript" src="/js/ui/1.8/ui/jquery.ui.widget.js"></script>
<script type="text/jscript" src="/js/ui/1.8/ui/jquery.ui.mouse.js"></script>
<script type="text/jscript" src="/js/ui/1.8/ui/jquery.ui.draggable.js"></script>

<style type="text/css">
    #draggable { width: 150px; height: 150px; padding: 0.5em;}
</style>

<script type="text/javascript">
$(function() {
    $( "#draggable" ).draggable();
});
</script>
</head>

<body>
<div class="demo">
    <div id="draggable" class="ui-widget-content">
    <p>Drag me around</p>
</div>
</div>
</body>
</html>
+2  A: 

The content types should be text/javascript, you currently have text/jscript for the jQuery UI files, like this:

<script type="text/javascript" src="/js/ui/1.8/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="/js/ui/1.8/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="/js/ui/1.8/ui/jquery.ui.mouse.js"></script>
<script type="text/javascript" src="/js/ui/1.8/ui/jquery.ui.draggable.js"></script>

Or include the entire jQuery UI library from the a CDN in one file, for example:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"&gt;&lt;/script&gt;

jscript is specifically for IE, but other browsers may or may not tolerate it and treat it as a JavaScript content type, for it to work everywhere stick with text/javascript.

Nick Craver
Thanks thousands of times. It works now. It is a typo but troubles me for a long time. Thanks again.
chunlu
@chunlu - Welcome :) be sure to [accept answers](http://meta.stackoverflow.com/questions/5234/how-does-accepting-an-answer-work) to this and your future questions if the answer resolves your problem :)
Nick Craver