title: Datepicker - close when clicking outside
body: <p>Datepicker doesn't close when clicking outside </p>
  
  <p>and if I select 10/09 and current date is 10/ 11 and refresh browser, </p>
  
  <p>then it shows current date 10/11 on     <code>&lt;input&gt;</code>     tag,</p>
  
  <p>but the selected date on datepicker keep showing 10/09</p>
  
  <p>How do I fix this?</p>
  
  <p>My code is below:</p>
  
  <pre><code>&lt;div class="form-inline" align="right"&gt;
    &lt;input type="text" name="datepicker" id="datepicker" class="form-control" value='&lt;%=selectDate%&gt;' onchange="hide()"&gt;
  
    &lt;script&gt;
      $input = $("#datepicker");
      $('#datepicker').datepicker({
        dateFormat: 'yyyy-mm-dd'
      });
      $input.data('datepicker').hide = function() {};
  
    &lt;/script&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>When I refresh the browser,</p>
  
  <p><a href="https://i.stack.imgur.com/bTUsT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bTUsT.png" alt="enter image description here"></a></p>