Target an area with Jquery

Target an area with Jquery

Hello everyone!

I've a button and this button opens a div. I've figured that when I target an area except this div it should be hide.
This is my codes but it doesn't work perfectly (actually it works slightly).
  1. <!--show hide div-->
  2.  $(function(){
  3.     
  4.     $('.mybutton').click(function(){
  5.       
  6.         $('.mydiv')        
  7.         .show()
  8.     });

  9.     
  10.     $('html').on('click', function(event){
  11.      
  12.         var target = $(event.target);

  13.         console.log(target);

  14.       
  15.         if (target.is('.mydiv') || target.parents('.mydiv').size() > 0)
  16.             return;

  17.         
  18.         $('.')
  19.             .hide()
  20.            
  21.     });
  22. });
  23.  
Anybody can fix that?