0

I've got image with ID h-plus.

When it's clicked it adds class d-block to image and close arrow.

When someone click close arrow then image and arrow dissaper.

Here's my code:

$(function() {
  $("#h-plus-1").click(function() {  
    $('#h-image-1').addClass("d-block");
    $('#h-close-arrow-1').addClass("d-block");
  });
});
  $(function() {
  $("#h-close-arrow-1").click(function() {     
    $('#h-image-1').removeClass("d-block");
    $('#h-close-arrow-1').removeClass("d-block");
  });
});

What I try to achive is to write jQuery script which will check if h-image have class d-block and if have this class then hide it when user will click anywhere except of h-image. Some sort of lightbox but without lightbox overlay effect.

I will be grateful for your help.

David
  • 53
  • 1
  • 1
  • 11
  • https://stackoverflow.com/questions/152975/how-do-i-detect-a-click-outside-an-element – epascarello Nov 03 '20 at 16:31
  • Trying to use it: $(document).click(function(event) { var $target = $(event.target); if(!$target.closest('#h-image-1').length && $('#h-image-1').hasClass("d-block")) { $('#h-image-1').removeClass("d-block"); $('#h-close-arrow-1').removeClass("d-block"); } }); But wont work – David Nov 03 '20 at 17:21

0 Answers0