Level 2
you will need to re-initialize the glightbox after you added images. e.g. glightbox.init()
function addImage() {
// Add image to the page dynamically
// ...
// Initialize glightbox on the new image
glightbox.init();
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am using a glightbox to view images. If the picture was on the page initially, then it perfectly initializes it and works with it. But if the picture is added dynamically, then it does not open the glightbox. How to initialize such pictures?
you will need to re-initialize the glightbox after you added images. e.g. glightbox.init()
function addImage() {
// Add image to the page dynamically
// ...
// Initialize glightbox on the new image
glightbox.init();
}
Please or to participate in this conversation.