Null is not an object (evaluating ‘e.length’)

So I am getting this error on my wordpress site and can’t work out what’s causing it. I have attached a screenshot of what shows up when the error is expanded though my gut feeling is that it’s got something to do with how the jQuery is loaded.

If anyone can give me any pointers or things to check – that’d be great.
enter image description here

Read More

Code in script.js:17

jQuery(document).ready(function($) {
    // set the container that Masonry will be inside of in a var
    var container = document.querySelector('#masonry');

    // create empty var msnry
    var msnry;

    // initialize Masonry after all images have loaded
    imagesLoaded( container, function() {
        msnry = new Masonry( container, {
            itemSelector: '.masonry-item'
        });
    });
});

Related posts

1 comment

  1. The error occurs on line 17 of scripts.js.

    There is something wrong with that line that is causing the Masonry plugin to try reading the length property on an object that is null.

    document.querySelector() will return null when it doesn’t find a match, so the problem is that it is looking for an element with id “masonry” that doesn’t exist.

    You should figure out why there isn’t an element with id “masonry” and correct that behavior. Perhaps look at a sample of the theme you are using and compare to see where #masonry needs to be.

Comments are closed.