Reputation: 77
I am using the light gallery plugin fro my website , while running the
$('#categoryImages').lightGallery().destroy(true);
I getting the console error
Uncaught TypeError: $(...).lightGallery(...).destroy is not a function
the below mentioned code snippet is my website code which am using for light gallery.
$subcategory) { $subcategoryImage= scandir($dir.strtolower($getCategory)."/".$subcategory); unset($subcategoryImage[array_search('.', $subcategoryImage, true)]); unset($subcategoryImage[array_search('..', $subcategoryImage, true)]); foreach ($subcategoryImage as $key => $value2) { $data['subcategoryImages'][]= $dir.strtolower($getCategory)."/".$subcategory."/".$value2;?>
<li class="col-xs-6 col-sm-4 col-md-3" data-responsive=" 375, 480," data-src="">
<img class="img-responsive" src="">
Jquery code
$('body').on('click', '.category', function() {
$('#categoryImages').lightGallery().destroy(true);
});
Upvotes: 0
Views: 836
Reputation: 1572
As the documentation it should be like that : http://sachinchoolur.github.io/lightGallery/docs/api.html#methods
var cI = $('#categoryImages');
cI.lightGallery();
$('body').on('click', '.category', function() {
cI.data('lightGallery').destroy(true);
});
Update fiddle : http://jsfiddle.net/n5w7eoxh/11/
Upvotes: 1
Reputation: 32354
You need to save a reference to your initialized plugin and then call destroy on that after the ajax is complete, after you call destroy you reinitialize the plugin
var gal = $('#categoryImages');
gal.lightGallery();
/...
request.done(function(data) {
//...
$('.ajxcategoryImages').html(subcategoryImages1); //append the results
gal.data('lightGallery').destroy(true);//destroy the current gallery
gal.lightGallery();//create a new one
/..
Upvotes: 1