Last updated: Mar 2, 2024
Reading time·2 min
The "$(...).slick is not a function" jQuery error occurs for multiple reasons:
To solve the error, make sure to load the jQuery
library before loading the
slick
library.
The libraries have to be loaded only once on the page, otherwise, the error is thrown.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <!-- ✅ Load slick CSS ✅ --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css" integrity="sha512-wR4oNhLBHf7smjy0K4oqzdWumd+r5/+6QO/vDda76MW5iug4PT7v86FoEkySIJft3XA0Ae6axhIvHrqwm793Nw==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <!-- ✅ Load slick theme CSS ✅ --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.min.css" integrity="sha512-17EgCFERpgZKcm0j0fEq1YCJuyAWdz9KUtv1EjVuaOz8pDnh/0nZxmU6BBXwaaxqoi9PQXnRWqlcDB027hgv9A==" crossorigin="anonymous" referrerpolicy="no-referrer" /> </head> <body> <div class="single-item" style="width: 30%"> <div>Content 1</div> <div>Content 2</div> <div>Content 3</div> </div> <!-- ✅ load jQuery ✅ --> <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous" ></script> <!-- ✅ load Slick ✅ --> <script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js" integrity="sha512-XtmMtDEcNz2j7ekrtHvOVR4iwwaD6o/FUJe6+Zq+HgcCsk3kj4uSQQR8weQ2QVj1o0Pk6PwYLohm206ZzNfubg==" crossorigin="anonymous" referrerpolicy="no-referrer" ></script> <script src="index.js"></script> </body> </html>
The order in which we loaded the scripts is very important. We loaded the scripts in the following order:
index.js
file.Here's the code for the index.js
file.
$(document).ready(function () { $('.single-item').slick({ dots: true, centerMode: true, }); });
If you open the page you will see the carousel load.
noConflict
mode of jQuery.// 👇️ using noConflict mode const $jq = jQuery.noConflict(); $jq(document).ready(function () { $jq('.single-item').slick({ dots: true, centerMode: true, }); });
Make sure you aren't loading the jQuery library twice. Loading the library twice will re-run the initialization process and will cause the error.
You can check if you're loading the scripts correctly by opening your Developer
tools by pressing F12
and clicking on the Console
tab.
If you see any 404
errors related to loading the jQuery scripts, then the path
to the file is incorrect.
Lastly, try to load the most recent versions of the jQuery and Slick libraries.
To solve the "$(...).slick is not a function" jQuery error, make sure to load
the jQuery
library before loading the slick
library.
The libraries have to be loaded only once on the page, otherwise, the error is thrown.