WordPress.org

Ready to get started?Download WordPress

Forums

jQuery Library not loading? (12 posts)

  1. tdevine33
    Member
    Posted 3 years ago #

    http://www.hvce.com/governmentnon-profit-solar-elecrtic/faq/

    for some reason the jQuery library doesn't seem to be loading in this site. If you view the source you can see that it most definitely is there but the FAQ section is supposed to be a slider and it isn't. I also tried writing a simple bit of jQuery code (below) just to see if the site would read it at all and it wouldn't.

    $(document).ready(function() {
        $('body').css('background', 'red');
    });

    Any thoughts? I know the library is in the <head> but why won't it read any jQuery code that I'm writing?

    Thanks for any help in advance!

  2. tdevine33
    Member
    Posted 3 years ago #

    sorry... stupid move just made here. There are two sites for sister companies and I posted the wrong one. The ACTUAL site is

    http://www.adksolar.com/governmentnon-profit-solar-elecrtic/faq/

  3. tdevine33
    Member
    Posted 3 years ago #

    bump?

  4. David Gwyer
    Member
    Posted 3 years ago #

    Your jQuery library is loading correctly it seems. I just entered the following in Firebug's console window:

    jQuery(document).ready(function($) {
        $('body').css('background', 'red');
    });

    And the bg turned red as expected.

    There could be many reasons why your slider is not working. You need to look up the demo code for the slider (if you have access to any) and follow it closely.

    But you can be sure now that jQuery is loading so that's not the issue. I noticed that you have Contact Form 7 installed. You could try disabling that temporarily as that has caused JS problems in the past (in fact I disable the JS load for Contact From 7 now).

  5. Janu Studio
    Member
    Posted 3 years ago #

    Try adding the jquery with this code... Place the js file in root of theme folder... I just copied this code for you from my site running already perfect...

    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.js"></script>

  6. Janu Studio
    Member
    Posted 3 years ago #

    n yes Try that code of jquery in static html if its working... if its broken it wouldnt even work in html...

  7. David Gwyer
    Member
    Posted 3 years ago #

    jQuery is already loading on his page as I stated above, that's not the problem.

    Also, you should really be adding JS libraries via the wp_enqueue_script() function. This is the recommended and 'safe' way to add JS files to your WordPress page(s).

    See here for more information:
    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

  8. tdevine33
    Member
    Posted 3 years ago #

    so when you right the jquery code starting with jQuery and use the function($) it works, but not when you start with $ and just have function(). Is this because of a conflicting library perhaps?

  9. tdevine33
    Member
    Posted 3 years ago #

    right = write... sorry its early and I'm still starting on my tea.

  10. s_ha_dum
    Member
    Posted 3 years ago #

    The $ alias is problematic because several libraries use it. To avoid the problem WordPress loads jQuery in "no conflict" mode. That means that the $ alias doesn't work and you have to load jQuery like David Gwyer did, defining the $ alias in a limited scope, or use jQuery.* every time you want to call a jQuery function. That is why you are having trouble with $.

  11. David Gwyer
    Member
    Posted 3 years ago #

    so when you right the jquery code starting with jQuery and use the function($) it works, but not when you start with $ and just have function(). Is this because of a conflicting library perhaps?

    As specified by the link from apljdi, this is the standard way for handling jQuery in WordPress to avoid conflicts with other JS libraries (i.e. Prototype).

    The great thing about the syntax I posted above is that you can easily cut/paste 3rd party snippets of jQuery code, which are nearly always written as above (using $).

    That's why I always use that particular syntax. :)

  12. Drkenny
    Member
    Posted 3 years ago #

    I also am having a jquery code problem issue is with the insert / upload icon in wordpress 3.1.2

    I just upgraded a few of my WP sites and now cant add images this is on most of my WP blogs is anyone else having this problem?
    in firebug it says that the wordpress console was having trouble with jQuery saying it was undefined this is on the dashboard page
    any help is welcome as i am not an experienced coder

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags