My new theme is store in \app\design\frontend\<your_vendor_name>/<your_theme_name>\
and i have added requirejs-config.js file in above location with follwoing contents:
var config = {
map: {
'*': {
megamenu: 'js/megamenu.min'
}
},
shim: {
'megamenu': {
deps: ['$']
}
}
};
-----------------------------------------------
my megamenu.js file uses $ for initiating jquery. How can i solve jquery reference issue?
?
hello @ruta
in your megamenu.js file you need to define jquery like below code
define( ['jquery'], function($) { /* * your code */ });
If my answer is useful Click kudos & Accept as Solution
Basically $ is an alias of jQuery() so when you try to call/access it before declaring the function, it will endup throwing this $ is not defined error . This usually indicates that jQuery is not loaded and JavaScript does not recognize the $. Even with $(document).ready , $ is still going to be undefined because jquery hasn't loaded yet.
To solve this error:
Load the jQuery library at the beginning of all your javascript files/scripts which uses $ or jQuery, so that $ can be identified in scripts .
There can be multiple other reasons for this issue: