Error in slick.js: "Uncaught TypeError: Cannot read property 'add' of null" Error in slick.js: "Uncaught TypeError: Cannot read property 'add' of null" ruby-on-rails ruby-on-rails

Error in slick.js: "Uncaught TypeError: Cannot read property 'add' of null"


That's due to calling init twice. This works without error:

$(".slider").not('.slick-initialized').slick()

Also, "silder" looks like a typo.

Relying on a timeout is also error-prone. Unfortunately, Internet Explorer uses a different event to tell you when the HTML elements and JS libraries have been loaded. There are many libraries to avoid the 100 or so lines of cross-browser code, but the popular and relatively small jQuery solves the timing issue like this:

$(function() {  // Handler for .ready() called. Put the Slick Slider etc. init code here.})