title: Close one DIV on opening another one
body: <p>What I am trying to achieve is to close one DIV when other DIV is opened (click open) with jQuery. Following is the HTML structure.</p>
  
  <p>I am also interested to know if, in this case multiple DOM elements can be controlled with a single function.</p>
  
  <p>HTML Structure</p>
  
  <pre><code>&lt;div class="region-selection"&gt;
      &lt;div class="region-search"&gt;&lt;h6&gt;REGION&lt;/h6&gt;&lt;/div&gt;
      &lt;div class="region-dropdown"&gt;&lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div id="top-login"&gt;
      &lt;a href="#" class="top-register"&gt;&lt;span&gt;REGISTER&lt;/span&gt;&lt;/a&gt;
      &lt;div class="company-registration-modal"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here, on clicking the class <code>.region-search</code> and its children, I could get the region-dropdown to slide down. I could also get the company registration model to click open as well. However, when the first DIV is active, when I click the second DIV, the first one remains active. I need to close it. </p>
  
  <p>I am also trying to use the same jQuery function to control both DOM. Is it possible? </p>
  
  <p>The jQuery is as follows</p>
  
  <pre><code>$(document).ready(function(){
  
      var $registration_dropdown=$('.company-registration-modal');
      var $registration_link=$('.top-register span, .fa-registered');
  
      $registration_dropdown.hide();
      $registration_link.on('click touchend', function(event){
  
          var target = $(event.target);
  
          if(target.is($registration_link)){
              $registration_dropdown.slideToggle(300);
              event.stopPropagation();
          }
      });
  
      $(document).click(function(e) {
          if ($(e.target).closest($registration_dropdown).length===0) {
              $($registration_dropdown).slideUp(300);
          }
      });
  
      $registration_dropdown.mouseleave(function(){
          $(this).delay(400).slideUp(300);
      });
  
  });
  </code></pre>
  
  <p>Similarly, I write a different function for the second DIV.</p>