When using window load function it says $ is not a function

So I am using a wordpress theme called : thalassa.

I went to this site and copied the portfolio.js code. (note: my portfolio.js is exactly the same except the first line)

Read More

portfolio.js :

$(window).load(function() {
/* ================ VERFIFY IF USER IS ON TOUCH DEVICE ================ */

if(is_touch_device()){
    $(".portfolio-image").on('click', function(e){                  
        $(this).find('.portfolio-hover').show();
    });
}

// function to check is user is on touch device
function is_touch_device() {
    return 'ontouchstart' in window // works on most browsers 
    || 'onmsgesturechange' in window; // works on ie10
}

/* ================ PORTFOLIO ISOTOPE FILTER ================ */

(function() {
    //ISOTOPE
    // cache container
    var $portfolioitems = $('#portfolioitems');
    // initialize isotope
    $portfolioitems.isotope({
        filter: '*',
        masonry: {
            columnWidth: 1,
            isResizable: true
        }
    });

    // filter items when filter link is clicked
    $('#filters a').click(function() {
        $('#filters li').removeClass('active');
        var selector = $(this).closest('li').addClass('active').end().attr('data-filter');
        $portfolioitems.isotope({
            filter: selector
        });
        return false;
    });
})();
});

Then I paste it into my own site and it says : $ is not a function.
Why does it work on that site and not on my site? What am I doing wrong? Before I added

$(window).load(function() {

I had

jQuery(document).ready(function($) {

It works but sometimes it bugs out. And on the site I linked it doesn’t.

Related posts

3 comments

  1. DO it like this way,

    ( function($) {
    
        //Code block here
        $(window).load( function() {
            // do Stuff
        });
    
        $(document).ready( function() {
            //Wiggle Wiggle
        });
    })(jQuery);
    
  2. $(window).load(function () {
     //something  
    

    });

    This function is depreciated, you can use :

     $(document).ready(function() {
     //something
    });
    
  3. Please use jQuery word insted of $ in wordpress.

    jQuery(window).load(function() {
    
    -------
    
    });
    

Comments are closed.