kalu
kalu

Reputation: 33

jQuery is not working in wordpress website

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.

Upvotes: 1

Views: 36

Answers (1)

Shiladitya
Shiladitya

Reputation: 12161

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.

Upvotes: 1

Related Questions