Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Dropdowns with Jade and Bootstrap gives me $(".dropdown-toggle").dropdown is not a function

I'm trying to get a Bootstrap dropdown working with my Jade layout. But actually I'm getting this error when I'm trying to execute $(".dropdown-toggle").dropdown in my Jade-File:

$ is undefined 
$(".dropdown-toggle").dropdown is not a function

Why do I get this error message?

layout.jade

!!! 5
html
  head
    title= title
    link(rel='stylesheet', href='/lib/bootstrap/css/bootstrap.min.css')

        script(src='lib/bootstrap/js/bootstrap.min.js')
        script(src='lib/jquery/jquery-1.7.1.min.js')

        meta(name='viewport', content='width=device-width', initial-scale='1.0')

    body!= body

index.jade

  div.navbar.navbar-fixed-top
  div.navbar-inner
    div.container
      a(data-toggle='collapse',data-target='.nav-collapse').btn.btn-navbar
      a(href='#').brand #{title}
      div.nav-collapse
        ul.nav
          li.active
            a(href='#') Home
          li
            a(href='#') Blog
          li
            a(href='#') Contact
          li(id='menu1').dropdown
            a(data-toggle='dropdown', href='#menu1').dropdown-toogle Dropdown
              b.caret
            ul.dropdown-menu
              li
                a(href='#') Test
              li
                a(href='#') Test2

script
  $('.dropdown-toggle').dropdown()
like image 447
fraherm Avatar asked Mar 08 '12 23:03

fraherm


People also ask

Why is dropdown not working in bootstrap?

Why is my drop down menu not working in bootstrap? Solution : The dropdown should be toggled via data attributes or using javascript. In the above program, we have forgotten to add a data attribute so the dropdown is not working. So add data-bs-toggle="dropdown" to toggle the dropdown.

How do I use dropdown toggle in bootstrap?

To open the dropdown menu, use a button or a link with a class of .dropdown-toggle and the data-toggle="dropdown" attribute. The .caret class creates a caret arrow icon (), which indicates that the button is a dropdown. Add the .dropdown-menu class to a <ul> element to actually build the dropdown menu.

What indicates dropdown functionality in bootstrap?

Dropdowns are toggleable, contextual overlays for displaying lists of links and more. They're made interactive with the included Bootstrap dropdown JavaScript plugin. They're toggled by clicking, not by hovering; this is an intentional design decision. Dropdowns are built on a third party library, Popper.

How do you add a dropdown toggle in HTML?

Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.


1 Answers

You need to load the jQuery core before the bootstrap -

script(src='lib/jquery/jquery-1.7.1.min.js')    
script(src='lib/bootstrap/js/bootstrap.min.js')
like image 65
Jay Blanchard Avatar answered Sep 26 '22 20:09

Jay Blanchard