I am working on this quite strange issue for several days now, and I really don't understand why that happens.
Basically, the environment is WordPress and I am including two js files:
vendor.js -> generated by gulp and all it does is concatenating bower libs together
myScript.js -> my code
What I know (with proof):
- The vendor file is included before my code (checked from the console)
- The plugin I am using is included in vendor.js (opened the file in a new tab in chrome)
- Both files are loaded correctly (i printed some debug console log and they are in the console)
BUT even if everything looks fine to me, the plugin is still undefined for whatever reason. The plugin I am using is this one: https://github.com/idiot/unslider
and the error i'm getting in the console is this:
Uncaught ReferenceError: unslider is not defined
This is the part of my code where I call and need this plugin:
jQuery(document).ready(function($) {
console.log("unslider is ", unslider);
$('#topBannerSlider').unslider({
autoplay: true,
delay: 10000,
keys: true,
nav: true,
arrows: {
prev: '<a class="unslider-arrow prev fa fa-arrow-circle-left"></a>',
next: '<a class="unslider-arrow next fa fa-arrow-circle-right"></a>'
}
});
$('#homePageTestimonialsCarousel').unslider({
autoplay: true,
delay: 20000,
keys: true,
nav: true,
arrows: false
});
}
and it does the same if I try to load it before jQuery(document).ready() event, like so:
console.log("unslider is ", unslider);
jQuery(document).ready(function($) {
$('#topBannerSlider').unslider({
autoplay: true,
delay: 10000,
keys: true,
nav: true,
arrows: {
prev: '<a class="unslider-arrow prev fa fa-arrow-circle-left"></a>',
next: '<a class="unslider-arrow next fa fa-arrow-circle-right"></a>'
}
});
$('#homePageTestimonialsCarousel').unslider({
autoplay: true,
delay: 20000,
keys: true,
nav: true,
arrows: false
});
}
Do you have any suggestion? what else can I try? what else can it be? I am really stuck and any help would be really appreciated. Thanks a lot
asyncordeferattribute set on the<script>tag which is loading the library? Please also check the console for errors, as there should be some clue as to why your code isn't working)missing at the end of your code. Not sure if this is unrelated issue