简体   繁体   中英

Uncaught ReferenceError: jQuery is not defined

I am getting this error only in chrome for superfish drop down menu. It works fine in Firefox, and IE. It does not work in Chrome. The menu instead of being horizontal list itself Vertical. domain name of clients actual site has been changed below for confidentiality

<script type="text/javascript" src="http://www.domainname.com/js/jquery.js"></script>
<script type="text/javascript" src="http://www.domainname.com/js/superfish.js"></script>
<script type="text/javascript" src="http://www.domainname.com/js/hoverIntent.js"></script>
<script type="text/javascript">
    // initialise plugins
jQuery(function(){
     jQuery('ul.sf-menu').superfish();
    });
</script>

I have even changed it to the following and does not work:

    <script type="text/javascript">
         $(document).ready(function(){
            $('ul.sf-menu').superfish();
         })
    </script>

I looked at the view source and it is referencing two header files. This could be causing the error. I am using magento. The menu is working on all pages of the site except the one page checkout.

Fixed! read below will post as answer when it lets me in 7 hrs

The issue was not with the javascript itself, but with the css for the superfish menu. The developer who designed the layout and coded the template listed the stylesheet for the superfish menu as:

    <link rel="stylesheet" type="text/css" href="http://www.domainname.com/css/superfish.css" media="screen">

After removing the "http://www.domainname.com" and leaving it as "/css/superfish.css" it fixed the menu.

The only reasons trying to use the symbol jQuery like that would cause a ReferenceError would be:

  1. If the script include for jQuery failed. Check your console for 404s and the like.

  2. If one of the later scripts actually deletes the jQuery window property, eg:

     delete window.jQuery; 

    Just setting jQuery to undefined (perhaps via noConflict ) wouldn't cause a ReferenceError , you'd get undefined is not a function or similar. But if you actually delete the property, then you would. (Except on IE, which won't let you delete properties from the window object.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM