Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX loaded content with lightbox2

I'm using the Lightbox2 script and the content of my page is loaded via an AJAX request.
I don't find any function to attach new images or initialize Lightbox2 after an AJAX request, How can I make that in order to use Lightbox2 for images loaded via AJAX ?

Léo

like image 383
leosw Avatar asked Dec 20 '22 13:12

leosw


1 Answers

I had to reinitialize lightbox in order to detect new images. I have done that like this:

window.lightbox.init();

I placed this code in my success handler of ajax call after I have added the new content:

contentContainer.empty().html(data);
like image 197
Ondrej Peterka Avatar answered Dec 30 '22 19:12

Ondrej Peterka