Title: jQuery error
Last modified: October 8, 2016

---

# jQuery error

 *  [GeniusStartup](https://wordpress.org/support/users/geniusstartup/)
 * (@geniusstartup)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/jquery-error-46/)
 * Hi,
 * Love the plugin but I’m having a problem when using quizzes in ajax mode.
 * I’m using the code below to load jQuery and other js scripts in the footer, rather
   than the header:
 *     ```
       wp_deregister_script('jquery');
       wp_register_script('jquery', '/wp-includes/js/jquery/jquery.js', false, false, true);
       wp_enqueue_script('jquery');
       ```
   
 * With that code running, I get this console error when clicking Show Results:
 * `Uncaught TypeError: Cannot read property 'length' of undefined`
 * Disabling the code above makes Watu work fine.
 * Am I right in thinking this is happening because the Watu JS in the head isn’t
   using _$( document ).ready()_?
 * If that’s correct, how can I add this? Thank you.

Viewing 14 replies - 1 through 14 (of 14 total)

 *  Plugin Author [Bob](https://wordpress.org/support/users/prasunsen/)
 * (@prasunsen)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8266535)
 * It uses document.ready(). What exactly is on the line where you get the error?
   
   Posting the URL here will be useful.
 *  Thread Starter [GeniusStartup](https://wordpress.org/support/users/geniusstartup/)
 * (@geniusstartup)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8267929)
 * Thanks for the quick reply.
 * The console error refers to line 165, which starts:
 * `for(x=0; x<Watu.qArr.length; x++) {`
 * Just noticed there’s also another error:
 * `Uncaught ReferenceError: jQuery is not defined`
 * being triggered by this part of the source code:
 *     ```
       var watuURL='';
       jQuery(function($){
       question_ids = "4,5";
       exam_id = 2;
       ```
   
 * Sorry, I can’t post a live link because the page is still being developed.
 *  Plugin Author [Bob](https://wordpress.org/support/users/prasunsen/)
 * (@prasunsen)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8267998)
 * As you see, moving jQuery at the bottom makes even document.ready not work. So
   you should not do it. Keep jQuery at top, many plugins rely on it.
 *  Thread Starter [GeniusStartup](https://wordpress.org/support/users/geniusstartup/)
 * (@geniusstartup)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8268455)
 * All other plugins work fine. Loading jQuery in the footer is common for speed
   optimization.
 * The bit of code causing the error isn’t using _document.ready_, it’s using
 * `jQuery(function($){`
 *  Plugin Author [Bob](https://wordpress.org/support/users/prasunsen/)
 * (@prasunsen)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8268494)
 * The fact that your other current plugins run fine does not mean that other plugins
   that you will install in the future will run fine.
 * jQuery(function($)) is jQuery’s equivalent to document.ready. We have no plans
   for changing it for the moment so if you want to use Watu you’ll need to keep
   jQuery in the head.
 *  Plugin Author [Bob](https://wordpress.org/support/users/prasunsen/)
 * (@prasunsen)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8268506)
 * Here is a discussion about the different document.ready syntaxes, although you
   can find them in the official jQuery docs as well:
 * [http://stackoverflow.com/questions/3528509/document-readyfunction-vs-function](http://stackoverflow.com/questions/3528509/document-readyfunction-vs-function)
 *  Plugin Author [Bob](https://wordpress.org/support/users/prasunsen/)
 * (@prasunsen)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8268520)
 * And here’s an example to see exactly how complicated is to use document.ready
   before including jQuery:
 * [http://writing.colin-gourlay.com/safely-using-ready-before-including-jquery/](http://writing.colin-gourlay.com/safely-using-ready-before-including-jquery/)
 * This is not worth the effort for us just to allow 0.001% to make minor speed 
   optimizations. jQuery must be loaded in the head, which is the standard WP behavior
   for a good reason.
 *  [ropezg](https://wordpress.org/support/users/ropezg/)
 * (@ropezg)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8641834)
 * Hello
    I think I’m having the same error and I’m not loading jquery in footer.
   I do use asynch tag on some scripts but this doesn’t seem to make a difference(
   turning it off didn’t bring a difference)
 * the JS error I’m getting:
 *     ```
       Uncaught TypeError: Cannot read property 'length' of undefined
           at Object.Watu.submitResult (/wp-content/plugins/watu/script.js:165)
       ```
   
 * `for(x=0; x<Watu.qArr.length; x++) {`
 * any ideas what might be causing this?
 *  Plugin Author [Bob](https://wordpress.org/support/users/prasunsen/)
 * (@prasunsen)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8641878)
 * Send me live URL to see it.
 *  [ropezg](https://wordpress.org/support/users/ropezg/)
 * (@ropezg)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8642221)
 * Hello
    here is the live link: [test](http://www.condom-sizes.org/sexual-health/online-std-test)
 * I will turn off jquery in few hours as I don’t want a broken quiz to be live 
   on the site
 * thank you for looking into it
 *  Plugin Author [Bob](https://wordpress.org/support/users/prasunsen/)
 * (@prasunsen)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8643500)
 * You have a fatal error on a Cloudflare script, no idea what is it:
 * TypeError: a.target.className.indexOf is not a function
 * [https://ajax.cloudflare.com/cdn-cgi/nexp/dok3v=f2befc48d1/cloudflare.min.js](https://ajax.cloudflare.com/cdn-cgi/nexp/dok3v=f2befc48d1/cloudflare.min.js)
 * It doesn’t work correctly, disable this optimization.
 *  [ropezg](https://wordpress.org/support/users/ropezg/)
 * (@ropezg)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8643655)
 * hi
    thank you for looking it. I think it’s the Rocket Loader™ optimization option.
   I turned it off but strangely then other errors popped out, maybe because the
   cache wasn’t fully cleared Will look into it more
 * thanks!
 *  [ropezg](https://wordpress.org/support/users/ropezg/)
 * (@ropezg)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8643679)
 * can I just ask how did you find the cloudflare error?
    that would be very useful
   to know…
 * The only thing I see in the Console (inspect element) is:
    `A Parser-blocking,
   cross-origin script, http://ajax.cloudflare.com/cdn-cgi/nexp/dok3v=f2befc48d1/
   cloudflare.min.js, is invoked via document.write. This may be blocked by the 
   browser if the device has poor network connectivity. See https://www.chromestatus.
   com/feature/5718547946799104 for more details.`
 * thanks a lot!
 *  Plugin Author [Bob](https://wordpress.org/support/users/prasunsen/)
 * (@prasunsen)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8644017)
 * I’m, using Firebug console in Firefox. It’s very useful for finding JS errors.

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘jQuery error’ is closed to new replies.

 * ![](https://ps.w.org/watu/assets/icon-128x128.png?rev=1680960)
 * [Watu Quiz](https://wordpress.org/plugins/watu/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/watu/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/watu/)
 * [Active Topics](https://wordpress.org/support/plugin/watu/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/watu/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/watu/reviews/)

 * 14 replies
 * 3 participants
 * Last reply from: [Bob](https://wordpress.org/support/users/prasunsen/)
 * Last activity: [9 years, 4 months ago](https://wordpress.org/support/topic/jquery-error-46/#post-8644017)
 * Status: not resolved