jQuery: Hide popup if click detected elsewhere

前端 未结 12 870
情书的邮戳
情书的邮戳 2020-12-02 14:33

I\'m trying to hide a div if the user clicks anywhere BUT the popup OR its children. This is the code I have so far:

$(\"body\").click(function(){
    var $t         


        
12条回答
  •  余生分开走
    2020-12-02 15:12

    Here's a potential solution for certain situations. The popup must have tabindex set for this to work and cannot have any "focusable" elements inside.

    $('a').click(function() {
        $('.popup').show().focus();
    });
    $('.popup').blur(function() {
        $(this).hide();
    });
    

    http://jsfiddle.net/d6zw3/

提交回复
热议问题