• How do I make wordpress use the latest version available to it rather than version 1.11 which it seems to load to by default.

    Surely WordPress 4.2.1 should be using version 2.x by now.

    I don’t just want tell it to get jquery from google servers as it’s important that it’s loaded in no-conflict mode.

    Thanks in advance

Viewing 7 replies - 1 through 7 (of 7 total)
  • I would not recommend deregistering core jQuery as it can cause all sorts of problems. But you certainly CAN if you wish.

    WordPress loads the jQuery version that it has been tested and shipped with. If you want to use a different version, you can simply deregister core jQuery and enqueue your own.

    Thread Starter c-m

    (@c-m)

    ah so wordpress 4.2.1 is only tested with jquery 1 which is old. But my code below won’t work unless I add jquery 2 to the head of my theme.

    $(document).ready(function () {
    
        $(window).scroll(function () {
            if ($(this).scrollTop() > 500) {
                $('.scrollup').fadeIn();
            } else {
                $('.scrollup').fadeOut();
            }
        });
    
        $('.scrollup').click(function () {
            $("html, body").animate({
                scrollTop: 0
            }, 900);
            return false;
        });
    
    });

    If de-registering jquery 1 is so bad, what are people to do?

    Can you try this and let me know if it works for you?

    jQuery(document).ready(function($) {
    
        $(window).scroll(function () {
            if ($(this).scrollTop() > 500) {
                $('.scrollup').fadeIn();
            } else {
                $('.scrollup').fadeOut();
            }
        });
    
        $('.scrollup').click(function () {
            $("html, body").animate({
                scrollTop: 0
            }, 900);
            return false;
        });
    
    });
    Thread Starter c-m

    (@c-m)

    I posted the wrong script.

    I think it’s the defer script that doesn’t work.

    <script type="text/javascript">
    function downloadJSAtOnload() {
    var element = document.createElement("script");
    element.src = "<?php bloginfo('template_directory'); ?>/js/misc1.js";
    document.body.appendChild(element);
    }
    if (window.addEventListener)
    window.addEventListener("load", downloadJSAtOnload, false);
    else if (window.attachEvent)
    window.attachEvent("onload", downloadJSAtOnload);
    else window.onload = downloadJSAtOnload;
    </script>

    I use this to defer loading misc.js that contains all of my custom js.

    You should really be using the jQuery ready() function to check for DOM load. This StackOverflow link looks to be doing exactly what you’re trying to do, which is load a js file only once the page has otherwise loaded.

    https://stackoverflow.com/questions/2829483/loading-javascript-file-after-jquery-ready

    I also noticed that you said “I use this to defer loading misc.js that contains all of my custom js”, but your code says it’s looking for misc1.js? Is that a typo?

    Also, jQuery 1 is not “old”, strictly speaking. There are a few minor differences between 1 and 2, true, but mostly v1 is used when you want the highest compatibility with people’s browsers. jQuery2 stripped out a lot of the “bloat” that was necessary for older browser support, and only supports IE9+. jQuery Browser Support

    jQuery 1 is still actively released, with the latest versions of 1 and 2 being released a little over a week ago. https://blog.jquery.com/2015/04/28/jquery-1-11-3-and-2-1-4-released-ios-fail-safe-edition/

    Thread Starter c-m

    (@c-m)

    Yeah it’s misc1.js that was just typo in the post. Thanks I’ll look as the stackoverflow link and see what I can come up with.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Loading jQuery’ is closed to new replies.