0

Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Document': '[object HTMLDocument]' is not a valid selector.

this is my code in main.js file.

require([ 'rellax'], function ($) {
    $(document).ready(function () {
    console.log("entered the function rellax");
    var rellax = new Rellax('.rellax', {
        callback: function (position) {
            console.log(position);
            }
        });
    });
});

This is my requirejs-config.js

var config = {

    deps: [
        "js/main"
    ],
    map: {
    '*': {
        slick: 'js/slick.min',
        rellax: 'js/rellax.min'
        }
    },
};
4
  • if i remove the $(document).ready(function () then it throws Uncaught ReferenceError: Rellax is not defined
    – Sylvester
    Commented Oct 4, 2017 at 8:48
  • 1. Add domReady! as a dependency rather than using the jQuery .ready method. 2. What happens if you remove the rellax code and dependency? That can narrow it down to either rellax itself or whether it's how you've added the JS.
    – Ben Crook
    Commented Oct 4, 2017 at 9:22
  • Hi ben, i remove .ready and added ['jquery', 'rellax', 'domReady!'], still its the same, gettng rellax undefined
    – Sylvester
    Commented Oct 4, 2017 at 9:42
  • please share your full path of js js/rellax.min Commented Oct 4, 2017 at 10:40

1 Answer 1

0

Try this:

require(['jquery', 'rellax', 'domReady!'], function ($, rellax, domReady) {
    console.log("entered the function rellax");

    var rellax = new Rellax('.rellax', {
        callback: function (position) {
            console.log(position);
        }
    });
});

I have added jQuery and domReady! as a dependency and removed the jQuery .ready() method.

If you are getting errors about rellax being undefined then it sounds like you're either using Rellax wrong or your paths are incorrect. If you still get the error, is the console log working?

8
  • Hi I am still getting the error as Rellax is not defined, the file is getting called for sure but looks like its not initialised
    – Sylvester
    Commented Oct 4, 2017 at 10:10
  • It sounds like it's either a problem with rellax or how you're using it, unless I'm missing something if this file and rellax are loading fine it doesn't sound like a Magento issue.
    – Ben Crook
    Commented Oct 4, 2017 at 10:14
  • I tried this with simple html and css. It seemed to work fine but here with requirejs it seems to be a problem. Any idea how to debug it?
    – Sylvester
    Commented Oct 4, 2017 at 10:27
  • It may even be an issue with Rellax: github.com/dixonandmoe/rellax/issues/61 and github.com/dixonandmoe/rellax/issues/22
    – Ben Crook
    Commented Oct 4, 2017 at 10:57
  • one of the issues being that it was not working as the rellax was called before defining, but in our case using requireJS that shouldnt happen, so what do i do here to resolve this, been stuck with this for 3 days already
    – Sylvester
    Commented Oct 5, 2017 at 5:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.