title: Multi Level Drop Down Bootstrap
body: <p>I'm already try this <a href="https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_js_dropdown_multilevel_css&amp;stacked=h" rel="nofollow noreferrer">Multi-Level Drop Down</a>. When I have 2 or more dropdown submenu. When I click first dropdown and then I click another dropdown, the first dropdown still open. I want when I click second dropdown, the first dropdown will close or when I click head of dropdown all sub-dropdown will close.</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-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt;
    &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;style&gt;
  .dropdown-submenu {
      position: relative;
  }
  
  .dropdown-submenu .dropdown-menu {
      top: 0;
      left: 100%;
      margin-top: -1px;
  }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
     
  &lt;div class="container"&gt;
    &lt;h2&gt;Multi-Level Dropdowns&lt;/h2&gt;
    &lt;p&gt;In this example, we have created a .dropdown-submenu class for multi-level dropdowns (see style section above).&lt;/p&gt;
    &lt;p&gt;Note that we have added jQuery to open the multi-level dropdown on click (see script section below).&lt;/p&gt;                                        
    &lt;div class="dropdown"&gt;
      &lt;button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"&gt;Tutorials
      &lt;span class="caret"&gt;&lt;/span&gt;&lt;/button&gt;
      &lt;ul class="dropdown-menu"&gt;
        &lt;li&gt;&lt;a tabindex="-1" href="#"&gt;HTML&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a tabindex="-1" href="#"&gt;CSS&lt;/a&gt;&lt;/li&gt;
        &lt;li class="dropdown-submenu"&gt;
          &lt;a class="test" tabindex="-1" href="#"&gt;New dropdown 1 &lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt;
          &lt;ul class="dropdown-menu"&gt;
            &lt;li&gt;&lt;a tabindex="-1" href="#"&gt;2nd level dropdown&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a tabindex="-1" href="#"&gt;2nd level dropdown&lt;/a&gt;&lt;/li&gt;
            &lt;li class="dropdown-submenu"&gt;
              &lt;a class="test" href="#"&gt;Another dropdown &lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt;
              &lt;ul class="dropdown-menu"&gt;
                &lt;li&gt;&lt;a href="#"&gt;3rd level dropdown&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href="#"&gt;3rd level dropdown&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/li&gt;
        &lt;li class="dropdown-submenu"&gt;
          &lt;a class="test" tabindex="-1" href="#"&gt;New dropdown 2 &lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt;
          &lt;ul class="dropdown-menu"&gt;
            &lt;li&gt;&lt;a tabindex="-1" href="#"&gt;2nd level dropdown&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a tabindex="-1" href="#"&gt;2nd level dropdown&lt;/a&gt;&lt;/li&gt;
            &lt;li class="dropdown-submenu"&gt;
              &lt;a class="test" href="#"&gt;Another dropdown &lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt;
              &lt;ul class="dropdown-menu"&gt;
                &lt;li&gt;&lt;a href="#"&gt;3rd level dropdown&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href="#"&gt;3rd level dropdown&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
  $(document).ready(function(){
    $('.dropdown-submenu a.test').on("click", function(e){
      $(this).next('ul').toggle();
      e.stopPropagation();
      e.preventDefault();
    });
  });
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://i.stack.imgur.com/2M3ZU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2M3ZU.png" alt="enter image description here"></a></p>