开发者

jQuery is not defined?

I have the following code in the body of my page. (I know it would be better to load in the header, but I don't have access to the header.)

<script src="javascript/jquery-1.5.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function(){
  alert('hello world');
});
</script>

Firebug shows that jquery-1.5.2.min.js is loading fine, and it was wgetted straight from the jQuery downloads page, so there should be no issues with the content. However, the script barfs on jQuery.noConflict() with:

Error: jQuery is not defined

I've tried moving this line in开发者_Go百科side (document).ready but it doesn't help. So, how can I check that jQuery has loaded without referring to jQuery? :)

I need to use jQuery in noConflict mode as there are scriptaculous scripts on the same page.

Thanks!


Without seeing the complete page it is tough to answer this one. However my best guess is that yes your jQuery libraries do (eventually) get downloaded, the next bit of script which fires and access jQuery object does so before jQuery scripts are ready. As a quick proof of concept can you try this simple (but very dirty hack) to see if I am on the right track?

<script src="javascript/jquery-1.5.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
setTimeout(function(){alert(jQuery);},1000);
</script>


You have to use $.noConflict(). Make sure you import the jquery script after scriptaculous, and call noConflict before making any scriptaculous calls.

http://api.jquery.com/jQuery.noConflict/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜