Jquery- Hide div

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

I have a div inside form something like

showing some information here
相关标签:
2条回答
  • 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 <div>. When you click inside that <div> though, you can stop the bubble from getting up to document by using event.stopPropagation()...so the .hide() doesn't fire, short and simple :)

    0 讨论(0)
  • 2020-12-09 11:45
    $(document).click(function(event) {
      var target = $( event.target );
    
      // Check to see if the target is the div.
      if (!target.is( "div#idshow" )) {
        $("div#idshow").hide();
        // Prevent default event -- may not need this, try to see
        return( false );
      }
    });
    
    0 讨论(0)
提交回复
热议问题