0

So what I'm trying to accomplish is that you close the popup by clicking anywhere outside of it. But as it is now, if you where to click on a < p> tag inside the popup, it also closes...

What I've got now is this:

$('html').click(function(e) {
    var popup = $('.popup');

    if(popup.length) {
        if(!$(e.target).is('.popup-content') || !$(e.target).is('.popup-content').find('*')) {
            popup.removeClass('in');

            setTimeout(function () {
                popup.remove();
            }, 300);
        }
    }
});

Obviously !$(e.target).is('.popup-content').find('*') doesn't seem to work. And the content will not be static...

Hopefully someone has a solution

Jason
  • 58
  • 4

1 Answers1

0

Try this :

$('html').click(function(e) {
    var popup = $('.popup');
    var clickedElement = e.target;
    var popupContent = ($(clickedElement).closest('.popup-content').length > 0)? true:false;
    if(popup.length > 0) {
        if(!popupContent) {
            popup.removeClass('in');

            setTimeout(function () {
                popup.remove();
            }, 300);
        }
    }
});
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57