title: How to close custom jquery drop down using like default select dropdown
body: <p>I am trying to close a custom jquery drop down on click of outside of dropdown, just like default behavior of  HTML select dropdown, I tried  to use the window click but that is creating trouble in opening the dropdown it self.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(".selected").click(function() {
    $(".custom-dropdown-list").toggleClass("open");
  });
  
  $(".custom-dropdown-list li").click(function() {
    var dataVal = $(this).attr("data-val");
    var dpText1 = $(this).children('.dp-val1').text();
    var dpText2 = $(this).children('.dp-val2').text();
    $(".selected").attr("data-val", dataVal);
    $(".selected .dp-val1").text(dpText1);
    $(".selected .dp-val2").text(dpText2);
    $(".custom-dropdown-list").removeClass("open");
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.custom-dropdown {
    width: 300px;
  }
  
  .selected {
    padding: 5px;
    cursor: pointer;
    min-height: 37px;
    background-color: #ccc;
  }
  
  .custom-dropdown-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: none;
  }
  
  .custom-dropdown-list.open {
    display: block;
  }
  
  .custom-dropdown-list li {
    padding: 5px;
    cursor: pointer;
  }
  
  .custom-dropdown-list li:hover {
    background: #f2f2f2;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="custom-dropdown"&gt;
    &lt;div class="selected" data-val=""&gt;
      &lt;div class="dp-val1"&gt;
        Selected Bank&lt;/div&gt;
      &lt;div class="dp-val2"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;ul class="custom-dropdown-list"&gt;
      &lt;li data-val="0"&gt;
        &lt;div class="dp-val1"&gt;Option Dp0&lt;/div&gt;
        &lt;div class="dp-val2"&gt;5879464954426 (LKP)&lt;/div&gt;
      &lt;/li&gt;
      &lt;li data-val="1"&gt;
        &lt;div class="dp-val1"&gt;Option Dp1&lt;/div&gt;
        &lt;div class="dp-val2"&gt;5879464954426 (LKP)&lt;/div&gt;
      &lt;/li&gt;
      &lt;li data-val="2"&gt;
        &lt;div class="dp-val1"&gt;Option Dp2&lt;/div&gt;
        &lt;div class="dp-val2"&gt;5879464954426 (LKP)&lt;/div&gt;
      &lt;/li&gt;
      &lt;li data-val="3"&gt;
        &lt;div class="dp-val1"&gt;Option Dp3&lt;/div&gt;
        &lt;div class="dp-val2"&gt;5879464954426 (LKP)&lt;/div&gt;
      &lt;/li&gt;
      &lt;li data-val="4"&gt;
        &lt;div class="dp-val1"&gt;Option Dp4&lt;/div&gt;
        &lt;div class="dp-val2"&gt;5879464954426 (LKP)&lt;/div&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>JSfiddle</strong></p>
  
  <p><a href="https://jsfiddle.net/5zgyouwL/1/" rel="nofollow noreferrer">https://jsfiddle.net/5zgyouwL/1/</a></p>