1

I'have a wordpress website using a " lightbox " gallery. It's not working properly. when we click on a Image it shows in lightbox. but the X / Close button is not working.

I have tried to make it work with this code, but not sure why it's not working.

here is the website url : http://www.mgrimmond.co.uk/gallery/

here is the code :

 jQuery(document).ready(function(){ 
    jQuery(".envirabox-close").click(function(){
         jQuery("#envirabox-container-1").css("display", "none");
    });
});

Any help would be appreciated.

Looking forward to your responses.

Kind Regards.

kalu
  • 33
  • 1
  • 6
  • You need to bind the close button after popup opened, there is no issue regarding jQuery, it working well – Jagjeet Singh Jul 09 '18 at 16:33
  • Possible duplicate of [Event binding on dynamically created elements?](https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – random_user_name Jul 09 '18 at 16:57

1 Answers1

1

Here you go with the solution.

Since your HTML code is getting generated dynamically, so click will not work directly. You need to delegate the click event from document to the target.

jQuery(document).ready(function(){ 
  jQuery("document").delegate(".envirabox-close", "click", function(){
     jQuery("#envirabox-container-1").css("display", "none");
  });
});

You can use on method as well

jQuery(document).ready(function(){ 
  jQuery("document").on("click", ".envirabox-close", function(){
     jQuery("#envirabox-container-1").css("display", "none");
  });
});

Hope this will help you.

Shiladitya
  • 11,210
  • 15
  • 22
  • 33