Custom image to lightbox on ajax request with getuikit.com
08:14 03 Oct 2026

I retrieve the image URL with an Ajax request. The lightbox with the existing image is already opened, and my goal is to replace the existing image with the retrieved one. Neither I nor AI could find any solution to do that.
I'm using getuikit v3.25.25
Below is my current solution that doesn't work. I got an infinite loading animation.

// Get the currently active lightbox panel instance
                        const activeLightboxPanel = UIkit.lightboxPanel(document.querySelector('.uk-lightbox.uk-open'));
                        
                        if (activeLightboxPanel) {
                            // Define custom image item
                            const imageItem = {
                                source: imageSrc,
                                caption: 'This is something new caption for the image',
                            };

                            // Push the new image into the active panel's items array
                            activeLightboxPanel.items = [];
                            activeLightboxPanel.items.length = 0;
                            activeLightboxPanel.items.push(imageItem);

                            // Immediately jump to the newly added image (last index)
                            console.log(activeLightboxPanel);
                            activeLightboxPanel.show(0);
                        } else {
                            console.warn('Could not find active lightbox panel');
                        }
lightbox getuikit