jQuery: Hide popup if click detected elsewhere

前端 未结 12 857
情书的邮戳
情书的邮戳 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 14:59

    I did something like the following. Hope it helps someone

    $('body').click(function(e) {
        $('className').click(function(){
             e.stopPropagation();
             $(this).data('clicked', true);
        })
    if(!$('.className').data('clicked')){
        // do sth
     } else {
        // do sth else
     }
    $('.className').data('clicked', false);
    

提交回复
热议问题