slick: Can't destroy slick - unslick function returns error
I’m unable to destroy a slick instance. Calling $('.your-slider').unslick();
returns Uncaught TypeError: Cannot read property 'parent' of null
on line 575 of slick.js. It would appear $slides
is undefined. Is anyone else seeing this issue?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 60 (6 by maintainers)
Not sure if anyone is still looking at this but I was stuck on it for an hour. I realised I have either read the way you call methods wrong or it’s changed.
Instead of
carousel.unslick();
you should usecarousel.slick("unslick");
In my case I needed to destroy slick at a certain window size. This worked for me:
Me too. For me works this:
Similar to @simonkitson I was calling the slick/unslick function on each resize so the function attempting to recreate the slider prevented the sliders removal.
My addition to @wtran is as follows:
@kenwheeler : I am getting error in IE 9 console because of unslick . *when doing $(‘.responsive’).slick(‘unslick’); getting error - *
*when doing $(‘.responsive’).unslick(); getting error - *
@inferusvv, for me too, but new slick dots added every time when using this code (i need to restore slick width on bootstrap tabs change event).
For me works this code: $slider.slick(‘unslick’).slick(…);
where … - slick settings varaible.
@nathanaelphilip try using @flesch91’s technique. check for the ‘slick-initialized’ class before calling unslick. The carousel is performing a kind of “init” on resizing and is temporarily unavailable. If you call unslick during that time, you get that error.
Yeah, calling methods was recently changed: https://github.com/kenwheeler/slick/releases/tag/1.4.0