Why won't my dropdown menu work

The following is the code I am using in codepen.io and for the life of me I can’t get my dropdown menu to toggle? Any help?

<nav class="navbar navbar-fixed-top">
  <div class="container">

    <a class="navbar-brand" href="#">Your Logo</a>

    <div class="navbar-collapse collapse navbar-responsive-collapse">
      <ul class="nav navbar-nav">
        <li class="active">
          <a href="#">Home</a>
        <li class="dropdown"><a data-toggle="dropdown" href="#">Portfolio<span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">home</a></li>
            <li><a href="#">home</a></li>
          <a href="#">About Me</a>

      <form class="navbar-form pull-left">
        <input type="text" class="form-control" placeholder="Search this site..." id="searchInput">
        <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
        <!--end button-->

      <ul class="nav navbar-nav pull-right">
          <a href="#"><span class="glyphicon glyphicon-user"> My Account</a>
      <!--end Navbar form--->
    <!--end Nav-collapse-->
  <!-- end container-->
<!--end navbar-->

Have you loaded both jquery and bootstrap.js into the JavaScript panel on codepen?

Yes, I have them both loaded. That was my first stop as well. I figured the jquery call must be missing.

To no avail…

@jlee1215 The order is important too, jQuery must be before the Bootstrap.js . Try building a navbar by copying the bootstrap example just to make sure your environment works. Then I would check your list opening and closing tags. I am commuting on a train now so hard to see with the shaking, but for some reason the opening and closing tags seem off somewhere. Maybe I am not seeing it right, but maybe look again.


Take a look at the example on the Bootstrap website. Maybe you’re not using a class or id properly.

Can you paste the link to your codepen?

Add this right at the bottom of your HTML


1 Like

are you adding your javascript and bootstrap files correctly ? Take a look at this article and make sure you are adding everything correctly. Let me know if this helps :slight_smile:

1 Like

@michaelhenderson Nice article, thank you for the link!

1 Like

No problem bud! I hope it helps you out !

Sorry for the delay, the evenings are harder for me to get online.

This is my codepen. I have inserted following your article Michael and still my dropdown is not working. I am not sure what I am doing wrong but I will keep fighting my way through here. I appreciate all the suggestions. I enjoy the iterative process and each suggestion has helped me learn a little.

There are some mistakes in your Javascript that needs to be corrected. The dropdown works after!

In Codepen, there is no need to wrap your JS code in script tags.Also, some things that pop out :

$(’.navbar a, footer a [href’#mypage’]").on(‘click’,function(event){

This line doesn’t work because you mixed quotation marks. If you have any double quotes in your selectors, you need to use single quotes to wrap them :

$(’.navbar a, footer a[href="#mypage"]’).on(‘click’,function(event){

and this :

(this.hash !++"") {

++ is incrementing a value. Here I suppose you wanted to check if hash was an empty string so it should be :

(this.hash !== “”) {

You also got a single quote mark somewhere that is breaking your code on line 9

1 Like


Thank you so much. I am more familiar with the HTML side of things so far so the JS was really throwing me. I actually copied that from someone who suggested it. It would have taken me forever to figure that out.

Thank you so much.

1 Like

Compare your navbar with the one from http://getbootstrap.com/components/

You have some important parts missing, such as the ‘hamburger’ icon for when the navbar collapses. I’d recommend reading through the example on the components page and fiddling with it to see what tags and attributes are used for what in the navbar.

There are other issues as well, but I’m on my phone so it’s hard to give a blow-by-blow account :slight_smile:

Thank you. I was experiencing the same issue and this worked!

1 Like

I was also struggeling to get bootstrap menu working. I loaded bootstrap under css and jquery and bootstrap under javascript. It didnt work. Then i tried to copy and paste older version of bootstrap and jquery in the setting from this other pen http://codepen.io/twittem/pen/lwbjC?editors=1100 and then it finally worked.

I had the same issue, the version of bootstrap and jquery were not causing the problem but the order in which I load the libraries made the difference. jQuery library should be added before the bootstrap library.

Thanks, you saved me

Thanks, the order in codepen threw me for a loop too… Don’t know how long this would have taken to solve without your post! :crazy_face:

Thank you. It work for me.