I’ve run into a problem where I have a responsive slider running on my site which has been added to an external .js file. I am running into an issue with a modal not popping up on the homepage because the page is looking for the slider which is only included on a couple of sub pages.
Chrome console is showing the following error:
Uncaught TypeError: undefined is not a function
Here is my current code:
JavaScript
x
5
1
$('.my-carousel').slick({
2
speed: 330,
3
slidesToShow: 4,
4
});
5
Advertisement
Answer
You can check if plugin has been loaded like this (it checks if given jQuery function exists):
JavaScript
1
4
1
if ($().slick) {
2
// .. your code
3
}
4
or
JavaScript
1
4
1
if ($.fn.slick) {
2
// .. your code
3
}
4