jQuery click off element event

后端 未结 15 1076
無奈伤痛
無奈伤痛 2020-12-13 00:25

I have a floating div that gets displayed, and I want it to be hidden when the user clicks off the div. This would be similar to the .hover() function callback when hoverin

15条回答
  •  心在旅途
    2020-12-13 00:36

    The Best way to do this is:-

        
    $(document).bind('click', function(e) {  
    
     var $clicked = $(e.target);
    
        if (!$clicked.parents().hasClass("divtohide")) {
            $(".divtohide").hide();
        }
    
    });
    

提交回复
热议问题