How can I detect if jQuery lightslider has been instantiated, and how to clear instance if yes

后端 未结 2 338
误落风尘
误落风尘 2021-01-23 15:05

I\'m using JQuery lightSlider. It works pretty well (well, actually, I had to jig the code a little bit, but enough of that for now).

What I am trying to achieve is to d

2条回答
  •  有刺的猬
    2021-01-23 15:50

    The $("#lightSlider").empty() or $("#lightSlider").html('') didn't work for some reason. The lightslider instances continued to pile up with every new form submission. I don't know why. Neither did the ("#lightSlider").lightslider().destroy() method seem to work, and that could be for some odd reason that I can't pinpoint, maybe something to do with the way I'm manipulating the DOM, I don't know.

    What finally worked was to nest the

      ...
    block within a block. Then, with each new form submission, I deleted the entire #lightSlider block with a $("#carousel-container").html(''); Then I dynamically re-created the entire
      ...
    with the new, updated content. Here's the working code:

            $("#carousel-container").html('');
            var lightsliderstring = "
      "; for(i=1;i\n"; } lightsliderstring += " \n"; lightsliderstring += "\n"; } lightsliderstring += "
    \n"; $("#carousel-container").html(lightsliderstring); $('#lightSlider').lightSlider({ auto: true, gallery: false, item: 1, loop: true, slideMargin: 0, thumbItem: 0 });

提交回复
热议问题