Jquery- Hide div

前端 未结 2 1829
广开言路
广开言路 2020-12-09 11:15

I have a div inside form something like

showing some information here
2条回答
  •  猫巷女王i
    2020-12-09 11:30

    You can do what you want like this:

    $(document).click(function() {
      $("#idshow").hide();
    });
    $("#idshow").click(function(e) {
      e.stopPropagation();
    });
    

    What happens here is when you click, the click event bubbles up all the way to document, if it gets there we hide the

    . When you click inside that
    though, you can stop the bubble from getting up to document by using event.stopPropagation()...so the .hide() doesn't fire, short and simple :)

提交回复
热议问题