Why is my dropdown menu with Bootstrap not working?

前端 未结 6 1083
野性不改
野性不改 2021-02-08 07:54

In my Rails application, I have the following code for a dropdown menu:

&l
6条回答
  •  情歌与酒
    2021-02-08 08:27

    I have had this issue for the whole day but was finally able to fix it. I applied the solution above (changing the order) and the dropdown worked. However, I noticed in the console there were errors (Uncaught ReferenceError: jQuery is not defined) due to the fact that bootstrap-sprockets was called before jQuery. I have found a solution that worked for me here

    Basically, I have included the following code below the required items in application.js as:

       //= require jquery
       //= require tether
       //= require jquery_ujs
       //= require bootstrap
       //= require bootstrap-sprockets
       //= require turbolinks
       //= require_tree .
    
    
       $(document).ready(function(){
           $('.dropdown-toggle').dropdown();
       });
    

    For me this worked like a charm. Hope that helps somebody!

提交回复
热议问题