0

I have two and more buttons with same class to destroy and rebuild the lightSlider script.

The CMS where I built it, is loading the images and ajax. As the javascript is loaded by ready it does not allow me to trigger the button for a second time.

What would be the way to destroy and rebuild it after ajax is loaded (ajaxComplete)?

  $(document).ready(function() {
    var slider = $('#publicMethods').lightSlider({
        slideMargin:4,
        slideWidth:200,
        loop:false
    });
    $('.load').click(function(){
        slider.destroy();    
    });
    $('.load').click(function(){
        if (!slider.lightSlider) {
            slider = $('#publicMethods').lightSlider({
                slideMargin:4,
                slideWidth:200,
                loop:false
            });  
        }
    });
  });
karadayi
  • 2,212
  • 2
  • 21
  • 36

1 Answers1

1
$('.load').click(function(){
    slider.destroy();    
});

Your attaching event handler to a DOM element directly , you need to attach to document instead, like :

$(document).on('click','.load',function(){
  //code here
})
Joaquin Javi
  • 880
  • 7
  • 12