Learn free online HTML5, javascript, and jquery Tutorials by Examples

Sunday 25 December 2016

How to close div clicking outside of it ?













<body>
    <div id="text">Hello</div>
</body>

<script>
     $(document).on('mouseup', function (e)
        {
           var text= $('#text');

              if (!text.is(e.target)
               && text.has(e.target).length === 0)
                  {
                     text.hide();
                  }
      });
</script>

No comments:

Post a Comment