0

I have applied slick slider in the phtml file but is giving error Uncaught TypeError: Cannot read property 'add' of null in browser

here is my code

<script type="text/javascript">

    require(['jquery', 'slick'], function($){ 
    jQuery(document).ready(function ($) {
           jQuery('.slickslider').slick({
      dots: false,
      infinite: false,
      speed: 300,
      slidesToShow: 3.1,
      settings: "unslick",
      slidesToScroll: 1,
      responsive: [
        {
          breakpoint: 1024,
          settings: {
            slidesToShow: 3.1,
            slidesToScroll: 1,
            infinite: false,
            dots: false
          }
        },
         {
          breakpoint:767,
          settings: {
            slidesToShow: 3.2,
            slidesToScroll: 1,
             dots: false
          }
        },
        {
          breakpoint: 600,
          settings: {
            slidesToShow: 3.1,
            slidesToScroll: 1,
             dots: false
          }
        },
           {
          breakpoint: 320,
          settings: {
            slidesToShow: 2.1,
            slidesToScroll: 1,
             dots: false
          }
        },
        {
          breakpoint: 480,
          settings: {
            slidesToShow: 2.1,
            slidesToScroll: 1,
             dots: false
          }
        }
        // You can unslick at a given breakpoint now by adding:
        // settings: "unslick"
        // instead of a settings object
      ]
    });
});
});
createSlick();

//Now it will not throw error, even if called multiple times.
 $(window).on( 'resize', createSlick );

then also it is giving an error

| improve this question | | | | |
1

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

$(".slickslider").not('.slick-initialized').slick()
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.