Decision
You can add css pointer-events: none to your button. This css property disables all events on the element. So something like this.
// Slick stuff ... onAfterChange: function(slide, index) { if(index === 4) { $('.slick-next').css('pointer-events', 'none') } else { $('.slick-next').css('pointer-events', 'all') } }
And something in the same guide for the .slick-prev element.
In this solution, you should get the function from the configuration and just put a link to it with something like this.
// Inside slick config onAfterChange: afterChange // Below somewhere var afterChange = function(slide, index) { //stuff here }
Also check if there is a way to get the length of the slider and check it instead of hardcoding 4 in the if . Perhaps you can do something like $('.slide').length
Edit
Here's how to implement the afterChange() function.
$(document).ready(function(){ $('.scrollable').slick({ dots: false, slidesToShow: 1, slidesToScroll: 3, swipeToSlide: true, swipe: true, arrows: true, infinite: false, }); $('.scrollable').on('afterChange', function (event, slick, currentSlide) { if(currentSlide === 2) { $('.slick-next').addClass('hidden'); } else { $('.slick-next').removeClass('hidden'); } if(currentSlide === 0) { $('.slick-prev').addClass('hidden'); } else { $('.slick-prev').removeClass('hidden'); } }) });
And some CSS, if you want to do animation, you have to do it here.
.slick-prev.hidden, .slick-next.hidden { opacity: 0; pointer-events:none; }