1

Sorry if this has been answered before, please link me if so, I couldn't find anything..

Basically, my jQuery worked fine on Bootstrap, up to the point I made a favicon. Now I think either my script / head tag alignment is off, so I tried to fix that for the past hour, but nothing is working.

Also putting the script at the end of the body, like normal, doesn't work. Not sure what I've done wrong here.

    <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">
    <meta name="description" content="">
    <meta name="author" content="">

    <title></title>

    <!-- jQuery -->
    <script src="js/jquery-1.12.4.min.js"></script>

    <!-- CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- Fonts -->
    <link href='https://fonts.googleapis.com/css?family=PT+Serif:400,700' rel='stylesheet' type='text/css'>
    <link href='https://fonts.googleapis.com/css?family=Exo+2:400,300,700,900,800' rel='stylesheet' type='text/css'>

    <!-- HTML5 Shim and Respond.js 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/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

 <!-- snip html -->

    <!-- jQuery Version -->
    <script src="js/jquery-1.12.4.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>




</body></html>

I know it's in there twice now, but neither works. What's wrong? :(

Edit: Dropdown doesn't work, this is the HTML for the dropdown:

        <!-- Navigation -->
 <nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#"><img src="img/logo/logo.png" class="img-responsive img-icon" /></a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse navbar-default">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form navbar-right" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

I changed some CSS for buttons, is that the problem?

/* Navbar Colours - Fixing Dropdown */

.nav > li a {
    color: #e97117;
}

.nav > li a:hover, a:focus {
    color: #e97117;
}

/* Navbar link Colours */

.navbar-default a:hover, a:focus {
    color: #e97117 !important;
}

/* Button Colour */

.btn {
    color: #fff;
    font-family: 'Exo 2', sans-serif;
}

.btn-default:hover,
.btn-default:focus {
    color: #e97117;
    background-color: transparent;
    border-color: #e97117;
}

.btn-secondary {
    color: #fff;
    background-color: transparent;
    border-color: #fff;
}

.btn-secondary:hover,
.btn-secondary:focus {
    color: #fff;
    background-color: #e97117;
    border-color: #fff;
}
10
  • What error are you getting that is indicating jQuery is no longer working? Commented Jun 6, 2016 at 17:24
  • There is no error, not even when I inspect element my page, but my drowndown isn't working in Bootstrap Commented Jun 6, 2016 at 17:26
  • It would help to include the code for your dropdown that isn't working. It's possible the issue is there Commented Jun 6, 2016 at 17:27
  • Yup just did, thanks. Commented Jun 6, 2016 at 17:27
  • Also added the CSS, which I doubt is a problem, but please tell me if it is Commented Jun 6, 2016 at 17:31

6 Answers 6

3

As @jdelaney indicated, you are missing a key ID.

<div class="collapse navbar-collapse navbar-default" id="bs-example-navbar-collapse-1">

Also, in your code example the path to your js and css is "page relative" rather than "site relative" or "fully qualified". So, if you are testing on a page that is not your "homepage" it is quite possible that you are not loading those assets at all. Do you happen to see 404 errors at all in the console?

Anyways, this example seems to work for me with the @jdelaney suggested edit.

.nav > li a {
    color: #e97117;
}

.nav > li a:hover, a:focus {
    color: #e97117;
}

/* Navbar link Colours */

.navbar-default a:hover, a:focus {
    color: #e97117 !important;
}

/* Button Colour */

.btn {
    color: #fff;
    font-family: 'Exo 2', sans-serif;
}

.btn-default:hover,
.btn-default:focus {
    color: #e97117;
    background-color: transparent;
    border-color: #e97117;
}

.btn-secondary {
    color: #fff;
    background-color: transparent;
    border-color: #fff;
}

.btn-secondary:hover,
.btn-secondary:focus {
    color: #fff;
    background-color: #e97117;
    border-color: #fff;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">
        <img src="img/logo/logo.png" class="img-responsive img-icon" />
      </a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse navbar-default" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a>
        </li>
        <li><a href="#">Link</a>
        </li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a>
            </li>
            <li><a href="#">Another action</a>
            </li>
            <li><a href="#">Something else here</a>
            </li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a>
            </li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a>
            </li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form navbar-right" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
    </div>
    <!-- /.navbar-collapse -->
  </div>
  <!-- /.container-fluid -->
</nav>

Sign up to request clarification or add additional context in comments.

6 Comments

Did I break the internet?
Are you saying that when you run this code snippet, the hamburger menu does not work? I ask because it does for me.
It works in the snippet fine, but not on my website I'm creating.
@AnneKok it works for me. What's not working for you?
@essaji it works fine for me in the snippet, but on my website it does not :(
|
1

Look at the line defining the collapse button:

<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">

Notice how it has data-target. That refers to what element to look for to collapse. If you look at the example on the Bootstrap site you'll notice that the main navbar content div has that ID (which your HTML is missing):

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

11 Comments

Gonna try this now, do I add the ID to the button ID line or the div?
@AnneKok You should add the id to the div. Check out the example given with Bootstrap
I did it, but it does not help.
@AnneKok Did you follow the advice of imvain2 and include bootstrap.min.js after jquery?
I did everything... I really dont get it :(
|
0

<!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">
    <meta name="description" content="">
    <meta name="author" content="">

    <title></title>

    <!-- jQuery -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

    <!-- CSS -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">

    <!-- Fonts -->
    <link href='https://fonts.googleapis.com/css?family=PT+Serif:400,700' rel='stylesheet' type='text/css'>
    <link href='https://fonts.googleapis.com/css?family=Exo+2:400,300,700,900,800' rel='stylesheet' type='text/css'>

    <!-- HTML5 Shim and Respond.js 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/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>
	
	<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
          </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse navbar-default">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form navbar-right" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>



</body></html>

First thing I would try is in the head:

change

<script src="js/jquery-1.12.4.min.js"></script>

to

<script src="js/jquery-1.12.4.min.js"></script>
<script src="js/bootstrap.min.js"></script>

4 Comments

@AnneKok it may not work but imvain2 is entirely right that you should be sure to include the Bootstrap JavaScript library after jQuery
Oh yeh I'm aware of that.
It seems to work. When you say it does not work, what do you mean?
Dropdown doesn't expand
0

I think the problem arises when you include JQuery two times. I can see in your code you're referencing <script src="js/jquery-1.12.4.min.js"></script> at the two places. Remove the one in the head tag & try again.

Comments

0

I tried your example html and css code and I only changed the inclusion of jquery and bootstrap (removed the jquery from section and included jquery and bootstrap from cdn) and as you can see it works without any problems.

Double check if your jquery and bootstrap are included correctly (path to the files / version conflicts?).

    /* Navbar Colours - Fixing Dropdown */

    .nav > li a {
        color: #e97117;
    }

    .nav > li a:hover,
    a:focus {
        color: #e97117;
    }


    /* Navbar link Colours */

    .navbar-default a:hover,
    a:focus {
        color: #e97117 !important;
    }


    /* Button Colour */

    .btn {
        color: #fff;
        font-family: 'Exo 2', sans-serif;
    }

    .btn-default:hover,
    .btn-default:focus {
        color: #e97117;
        background-color: transparent;
        border-color: #e97117;
    }

    .btn-secondary {
        color: #fff;
        background-color: transparent;
        border-color: #fff;
    }

    .btn-secondary:hover,
    .btn-secondary:focus {
        color: #fff;
        background-color: #e97117;
        border-color: #fff;
    }
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title></title>

    <!-- CSS -->
    <link  href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">

    <!-- Fonts -->
    <link href='//fonts.googleapis.com/css?family=PT+Serif:400,700' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Exo+2:400,300,700,900,800' rel='stylesheet' type='text/css'>

    <!-- HTML5 Shim and Respond.js 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="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>
    <body>

        <!-- Navigation -->
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#"><img src="img/logo/logo.png" class="img-responsive img-icon" /></a>
                </div>

                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse navbar-default">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
                        <li><a href="#">Link</a></li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="#">Action</a></li>
                                <li><a href="#">Another action</a></li>
                                <li><a href="#">Something else here</a></li>
                                <li role="separator" class="divider"></li>
                                <li><a href="#">Separated link</a></li>
                                <li role="separator" class="divider"></li>
                                <li><a href="#">One more separated link</a></li>
                            </ul>
                        </li>
                    </ul>
                    <form class="navbar-form navbar-right" role="search">
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Search">
                        </div>
                        <button type="submit" class="btn btn-default">Submit</button>
                    </form>
                </div>
                <!-- /.navbar-collapse -->
            </div>
            <!-- /.container-fluid -->
        </nav>

        <!-- jQuery Version -->
        <script src="//code.jquery.com/jquery-1.12.4.min.js"></script>

        <!-- Bootstrap Core JavaScript -->
        <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

    </body>

9 Comments

thats not clear to my why. did you copy&past to your local installation or does the code also not work if you click to "Run code snippet" and then click to "Full page"?
The code works fine on the snippet, but does not if I copy and paste it into my own code.
Do you have any error messages in your browser's console? If you try the above code in a local file replace all // inlcudes to https:// and it should work.
Do you try it in a plain html file or do you have any CMS where you included the code? If you use a CMS please post the not working html from your generated page source.
No CMS, just running it locally. There are 0 errors in the console. I've checked them a thousand times, and it never gives me an error.
|
0

The problem was in the CSS.

I had added an overflow:hidden function which I read over because I was tunnel visioned onto jQuery.

J Delaney helped me find it and it's all fixed now.

Thanks everyone that tried to help me! You couldn't possibly have known without the whole code, but I still really appreciate your help!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.