Skip to content Skip to sidebar Skip to footer

Typeerror: $(...).lightgallery(...).destroy Is Not A Function

I am getting this error from firefox: TypeError: $(...).lightGallery(...).destroy is not a function I am using following plugin for play video and show image gallery https://gith

Solution 1:

The following code works for me:

$lg.on('onBeforeClose.lg',function(event, index, fromTouch, fromThumb){
    try{$lg.data('lightGallery').destroy(true);}catch(ex){};
});

Solution 2:

For destroy data you should add data attribute to your gallery then destroy it, for example if you apply gallery to all links:

var myGallery = 'body',
    lightgallery = function() {
         $( myGallery ).attr('data-lightGallery', '1');
         $( myGallery ).lightGallery({selector: 'a[href$=".jpg"], a[href$=".jpeg"], a[href$=".png"], a[href$=".gif"]'});
    };

Then:

$( myGallery ).data('lightGallery').destroy(true);
lightgallery();

Solution 3:

If it is written like most plugins/widgets, you should be calling the destroy method like this.

$("#lightGallery2").lightGallery("destroy");

Solution 4:

You have to use the following method to destroy lightgallery version 1.2.x.

var$lg = $('#lightGallery2');

$lg.lightGallery({
  selector : '.image_gallery',
  videojs: true,
  download: false
});

$lg.data('lightGallery').destroy(true);

Here is the docs

Solution 5:

I simply created a global variable. It allows me to perform the desired function.

varPLUGIN; // global variable
...
if(PLUGIN) PLUGIN.data('lightGallery').destroy(true); // destroy PLUGIN = $("#lightGallery2").lightGallery();

Post a Comment for "Typeerror: $(...).lightgallery(...).destroy Is Not A Function"