ChiranSJ ChiranSJ - 3 months ago 14
jQuery Question

Top Navigation Created with Bootstrap Does not Collapse the Sub Menus

I have created a top navigation with a Navbar Header, 4 main links one with a drop down submenu and the caret.

The drop down submenu is not collapsing. I have tried to find the issue but couldn't find it. Please refer the below code snippet.



<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap with HTML</title>

<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
</script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->

</head>

<body>

<!-- Navbar with Dropdown Menus -->
<!-- Start Navbar Top -->
<nav class="navbar navbar-default">
<div class="container">
<!-- Toggle buttons snippet - This will define the toggle buttons of the navigation when the screen gets smaller -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- End of Toggle button snippet -->

<!-- The Site Name or Brand name snippet -->
<a class="navbar-brand" href="www.youtube.com" target="_blank">The Bootstrap Site with HTML</a>
<!-- End of brand name snippet -->

<!-- The below defines the navigation links in the Navbar. From this point you can create the links for the navigation -->
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Home</a>
</li>
<li><a href="#">Technologies</a>
</li>
<li><a href="#">Partners</a>
</li>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="drop-down">Products <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">SaaS</a>
</li>
<li><a href="#">PaaS</a>
</li>
<li><a href="#">Cloud</a>
</li>
<li><a href="#">IofT</a>
</li>
</ul>
</li>
</ul>
</div>
<!--End of the navigation links in the Navbar -->

</div>
</nav>
<!-- End of Navbar Top -->


</body>

</html>




Answer

The data-toggle="drop-down" should bedata-toggle="dropdown" and it all works fine now.

Check it out and let me know your feedback. Thanks!

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
  <title>Bootstrap with HTML</title>

  <!-- Bootstrap -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
  </script>
  <!-- Include all compiled plugins (below), or include individual files as needed -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->

</head>

<body>

  <!-- Navbar with Dropdown Menus -->
  <!-- Start Navbar Top -->
  <nav class="navbar navbar-default">
    <div class="container">
      <!-- Toggle buttons snippet -  This will define the toggle buttons of the navigation when the screen gets smaller -->
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <!-- End of Toggle button snippet -->

      <!-- The Site Name or Brand name snippet -->
      <a class="navbar-brand" href="www.youtube.com" target="_blank">The Bootstrap Site with HTML</a>
      <!-- End of brand name snippet -->

      <!-- The below defines the navigation links in the Navbar. From this point you can create the links for the navigation -->
      <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
          <li><a href="#">Home</a>
          </li>
          <li><a href="#">Technologies</a>
          </li>
          <li><a href="#">Partners</a>
          </li>
          <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Products <b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="#">SaaS</a>
              </li>
              <li><a href="#">PaaS</a>
              </li>
              <li><a href="#">Cloud</a>
              </li>
              <li><a href="#">IofT</a>
              </li>
            </ul>
          </li>
        </ul>
      </div>
      <!--End of the navigation links in the Navbar -->

    </div>
  </nav>
  <!-- End of Navbar Top -->


</body>

</html>