Hide when clicking on a document, except when clicking on a div

I want to hide the div when I click on a document, but I do not want to hide this div when someone clicks on it or clicks on a link or button in it. In addition, I have some links inside this set of divs to prevent the click (return false;) action and send an ajax request.

I tried:

$(document).click(function(e) {
      $('#bubble').hide();
});

$('#bubble').click(function(e) {
    return false;
});

It works fine, but links and buttons under #bubble do not work.

+3
source share
1 answer

Instead, return false;use event.stopPropagation()as follows:

$('#bubble').click(function(e) {
  e.stopPropagation();
});

click document, , , , return false;. , , - , :)

+5

Source: https://habr.com/ru/post/1753322/


All Articles