Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick Carousel Uncaught TypeError: $(...).slick is not a function

Somehow I'm unable to use slick carousel (http://kenwheeler.github.io/slick/) correctly.

I'm getting the following error:

Uncaught TypeError: $(...).slick is not a function 

I'm running the following code in my javascript file:

function initSlider(){     $('.references').slick({         dots: false,         infinite: true,         speed: 300,         slidesToShow: 1,         autoplay: true,         prevArrow: '<div class="slick-prev"><i class="fa fa-chevron-left"></i></div>',         nextArrow: '<div class="slick-next"><i class="fa fa-chevron-right"></i></div>'     }); } 

I've included the latest jQuery version (2.1.4) with bower. I've also tried including the jQuery CDN in the head of my layout template file, but that didn't resolve anything either.

The only thing strange that could mean something is that when I don't use a function to call the slider, it does work but it gives me the error:

Uncaught TypeError: Cannot read property 'add' of null 

I found out that that means that the code has been loaded before the DOM was loaded, which is correct (I think).

Thanks in advance!

Edit: I've created a JSFiddle from my code: https://jsfiddle.net/brz30e77/

EDIT2: The error persisted every now and then when adding new function to my JS file. I ultimately stripped my concatenated JS file and found out that there were two versions of jQuery being loaded, of which one was very, very old.

like image 877
Sanderfish Avatar asked Aug 03 '15 14:08

Sanderfish


People also ask

How do I import slick carousel?

I install jquery via npm, so that the slick-carousel could run and I install it with npm install jquery --save , so that (from what I've gathered) it's included in dependencies in my package. json file. Then I install slick carousel in the same way, using npm install slick-carousel --save.

Is not a function Typeerror is not a function?

This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.

Is not a function jQuery?

on if not a function" jQuery error occurs for 2 main reasons: Loading an old version of the jQuery library that doesn't support the on function. Loading a library that overrides the value of the dollar sign $ variable.


2 Answers

I found the solution myself later, so I placed it as an answer:

The error persisted every now and then when adding new function to my JS file. I ultimately stripped down my concatenated JS file and found out that there were two versions of jQuery being loaded, of which one was very, very old.

like image 96
Sanderfish Avatar answered Oct 04 '22 12:10

Sanderfish


Recently had the same problem: TypeError: $(...).slick is not a function

Found an interesting solution. Hope, it might be useful to somebody.

In my particular situation there are: jQuery + WHMCS + slick. It works normal standalone, without WHMCS. But after the integration to WHMCS an error appears.

The solution was to use jQuery in noConflict mode.

Ex: Your code:

$(document).ready(function() {    $('a').click( function(event) {     $(this).hide();     event.preventDefault();   }); }); 

Code in noConflict mode:

var $jq = jQuery.noConflict(); $jq(document).ready(function() {    $jq('a').click( function(event) {     $jq(this).hide();     event.preventDefault();   }); }); 

The solution was found here: http://zenverse.net/jquery-how-to-fix-the-is-not-a-function-error-using-noconflict/

like image 42
alexfrize Avatar answered Oct 04 '22 12:10

alexfrize