title: jQuery toggle (Click to show one div while hiding others)
body: <p>The basic idea is that I have a bunch of div's in which each can be toggled (show/hide).</p>
  
  <p>When one div is toggled I'd like for other div's that are currently being shown to hide, thus only allowing one single div to be shown at a time.</p>
  
  <p>In addition I'd like to be able to click outside the element to hide the open div as well.</p>
  
  <p>Just to make things clearer I provided an example which currently does everything I want except closing a div when opening another (Only one div open at a time functionality):</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>$(document).ready(function(){
  
    $('div.dropdown').each(function() {
      var $dropdown = $(this);
  
      $("a.dropdown-link", $dropdown).click(function(e) {
        e.preventDefault();
        $("div.dropdown-container", $dropdown).toggle();
        return false;
      });
  
  });
      
    $('html').click(function(){
      $("div.dropdown-container").hide();
    });
       
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div id="dropdown-1" class="dropdown dropdown-processed"&gt;
    &lt;a class="dropdown-link" href="#"&gt;Options&lt;/a&gt;
    &lt;div class="dropdown-container" style="display: none;"&gt;
      &lt;ul&gt;
        &lt;li&gt;Item 1&lt;/li&gt;
        &lt;li&gt;Item 2&lt;/li&gt;
        &lt;li&gt;Item 3&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div id="dropdown-2" class="dropdown dropdown-processed"&gt;
    &lt;a class="dropdown-link" href="#"&gt;Options&lt;/a&gt;
    &lt;div class="dropdown-container" style="display: none;"&gt;
      &lt;ul&gt;
        &lt;li&gt;Item 1&lt;/li&gt;
        &lt;li&gt;Item 2&lt;/li&gt;
        &lt;li&gt;Item 3&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div id="dropdown-3" class="dropdown dropdown-processed"&gt;
    &lt;a class="dropdown-link" href="#"&gt;Options&lt;/a&gt;
    &lt;div class="dropdown-container" style="display: none;"&gt;
      &lt;ul&gt;
        &lt;li&gt;Item 1&lt;/li&gt;
        &lt;li&gt;Item 2&lt;/li&gt;
        &lt;li&gt;Item 3&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>