Hiding a layer when clicking anywhere on page except the layer

后端 未结 4 1804
孤独总比滥情好
孤独总比滥情好 2021-01-29 01:35
$(\'body\').click(function() {
//hide layer code here
});

This will hide the layer.

But I don\'t want the layer to be hidden when I click insid

4条回答
  •  Happy的楠姐
    2021-01-29 01:55

    I think the more elegant way is this:

    $('body').click(function(event) {
    // hide layer code here
    });
    $('#layer').click(function(event) {
    event.stopPropagation();
    });
    

提交回复
热议问题