Search code examples
javascriptjqueryjquery-uiowl-carouselowl-carousel-2

How to empty items from owlCarousel?


I have an model where is I am showing some couple of images are showing in owlCarousel div. But problem is that when I close that model and again open it again. then the images are append to previous images. So I want to do something happen to clear all items from previous model and reinit that owlCarousel. I have tried :

var $carousel = $(".edit-manage-carousel");
for (var i =0; i<100; i++) {
  $carousel.trigger('remove.owl.carousel', i );
}

Solution

  • You are doing wrong.

    Here is correct way to do so.

    for (var i=0; i<$('.item').length; i++) {
       $(".edit-manage-carousel").trigger('remove.owl.carousel', [i])
                                 .trigger('refresh.owl.carousel');
    }