What could be the reason for the malfunctioning of this Bootstrap 2.3.2 dropdown menu?

I can't seem to get a dropdown menu working as the fourth element in the navigation bar on my website. Despite referencing the Bootstrap documentation, I'm still struggling with it. Here's a screenshot of the issue.

This is the code I currently have:

application.html.erb

<nav id="main_nav">
    <div id="logo"><%= link_to image_tag('logo.jpg', size: "40x40", alt: "College Inside View"), '/' %></div>
    <ul>
        <li><%= link_to 'Colleges', '/colleges' %></li> 
        <li> &#8226 </li>
        <li><%= link_to 'About College', '/about-college/college-life/1' %></li> 
        <li> &#8226 </li>
        <li><%= link_to 'Advice', '/advice' %></li>
        <li> &#8226 </li>
        <div class="dropdown">
            <li><a href="#" class="dropdown-toggle" data-toggle="dropdown">
               Tools 
               <b class="caret"></b>
            </a></li>
            <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
                <li><a tabindex="-1" href="#">Action</a></li>
                <li><a tabindex="-1" href="#">Another action</a></li>
                <li><a tabindex="-1" href="#">Something else here</a></li>
                <li class="divider"></li>
                <li><a tabindex="-1" href="#">Separated link</a></li>
            </ul>
        </div>
    </ul>
    <%= form_tag("/search", :method => 'get', :id => 'search_text', :class => 'form_search ui-autocomplete') do -%> 
        <%= search_field_tag :search, params[:search], :placeholder => 'enter college', :id => "search_field", :class => 'input-medium search-query ui-autocomplete' %>
    <% end -%>
</nav>

I also have

$('.dropdown-toggle').dropdown();
in my JavaScript file.

What am I missing or doing wrong?

Edit: After attempting this adjustment, I encountered this issue:

<nav id="main_nav">
    <div id="logo"><%= link_to image_tag('logo.jpg', size: "40x40", alt: "College Inside View"), '/' %></div>
    <div class="dropdown">
        <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
            <li><%= link_to 'Colleges', '/colleges' %></li> 
            <li> &#8226 </li>
            <li><%= link_to 'About College', '/about-college/college-life/1' %></li> 
            <li> &#8226 </li>
            <li><%= link_to 'Advice', '/advice' %></li>
            <li> &#8226 </li>
            <li class="dropdown-submenu">
                <a tabindex="-1" href="#">More options</a>
                <ul class="dropdown-menu">
                    <li><a tabindex="-1" href="#">Action</a></li>
                    <li><a tabindex="-1" href="#">Another action</a></li>
                    <li><a tabindex="-1" href="#">Something else here</a></li>
                    <li class="divider"></li>
                    <li><a tabindex="-1" href="#">Separated link</a></li>
                </ul>
            </li>
        </ul>
    </div>
    <%= form_tag("/search", :method => 'get', :id => 'search_text', :class => 'form_search ui-autocomplete') do -%> 
        <%= search_field_tag :search, params[:search], :placeholder => 'enter college', :id => "search_field", :class => 'input-medium search-query ui-autocomplete' %>
    <% end -%>
</nav>

Answer №1

Your HTML structure may not be in line with what bootstrap expects due to poor formatting.

Refer to the Sub Menus or Drop Downs section and make use of the valid HTML example provided:

<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
  ...
  <li class="dropdown-submenu">
    <a tabindex="-1" href="#">More options</a>
    <ul class="dropdown-menu">
      ...
    </ul>
  </li>
</ul>

It is important not to have a div directly inside a ul. Instead, nest your second level ul within a li. See explanation here.

View an example at: http://www.bootply.com/120623

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Images with varying heights: A bug in Chrome and Safari

I have a div that is absolutely positioned from the top and bottom of the screen. The images inside the div are set to scale to fill the height, while maintaining proportionate width. The images are displayed inline, and I've added white-space:nowra ...

"The power of Node JS in handling JSON data and gracefully

I'm having trouble extracting a specific part of a JSON object in Node JS. When I print the response body, the entire object is displayed correctly. However, when I try to access object.subsonic-response, it returns NaN. I've spent a lot of time ...

How can one effectively incorporate a 'toJson' function in TypeScript?

Does anyone know the best approach for adding a toJson function to a custom class? I've considered implementing functions like Foo.toJson, Foo.toJsonObject, or Foo.jsonify. Some examples suggest using a serializer. Is that necessary, or is there a mo ...

Creating a tool to display mouse coordinates as a pointer on an HTML5 canvas

I'm struggling with mouse coordinates while working on canvas in HTML5. My approach involves using JavaScript for drawing on the canvas. Below is my current code to track the mouse pointer within the canvas: $('#canvasID').mousedown(functi ...

Having trouble getting ng-click to function properly in TypeScript

I've been struggling to execute a function within a click function on my HTML page. I have added all the TypeScript definition files from NuGet, but something seems to be going wrong as my Click Function is not functioning properly. Strangely, there a ...

Grab the current URL using useRouter in a Next.js app

I am using userouter to obtain the URL of the current page and then utilizing the clipboard to copy it. However, I am encountering an issue where the copied content shows as object object instead of the expected URL. Can someone please help me identify w ...

Techniques for transferring child properties and values to parent components upon the screen being initialized

Is there a way to pass property values from a child component to a parent component when the react app is first loaded? In my scenario, I have a parent component named app.js that renders a home component containing a JSON component. Initially, upon loadi ...

Class methods cannot be invoked within their constructor

I'm currently facing challenges with implementing my express router. This is a "subrouter" of my main router, hence I need to extend express.Router. Here's an example of the code (simplified to include only one method): import express from "expr ...

Uncovering the secrets of extracting form parameters with jquery.ajax in asp.net

In search of a method to extract form parameters in C# similar to Java's request.getParameter("blah"). I am currently serializing my form with jQuery and sending it to a web method, but I need assistance in extracting the data. Using ajax. $("#btn" ...

I'm unable to modify the text within my child component - what's the reason behind this limitation?

I created a Single File Component to display something, here is the code <template> <el-link type="primary" @click="test()" >{{this.contentShow}}</el-link> </template> <script lang="ts"> imp ...

What is the best way to halt a specific function in jQuery?

I recently developed a website for my photographer friend, and I implemented a feature where the home page is initially blurred. Visitors can click a button to unblur the content. While the functionality works smoothly, there's one issue - every time ...

javascript - The onmessage event will not trigger when using a Java server

I have encountered an issue with my Java server and JavaScript websocket client. Despite trying various solutions from this site, I am still unable to resolve the problem. So, I decided to share my code here in hopes of getting some assistance. The proble ...

What is the method to retrieve the name of a clicked button using JavaScript?

There are 2 <div> elements containing a minimum of 81 buttons each, all having the same class. However, they have unique ids and names. I am currently experimenting with ways to display an alert message showing the name of the button that is being ...

Determine the precise location of a screen element with jQuery

Can anyone help me determine the precise position of an element on the current visible screen using jQuery? My element has a relative position, so the offset() function only gives me the offset within the parent. Unfortunately, I have hierarchical divs, ...

Eliminate unnecessary spaces in the input field located below the provided text

In the html code, I have an input field that looks like this: https://i.sstatic.net/DsD4y.png This is the CSS for the input fields: .form-control-1 { display: block; margin: 0 auto; width: 30%; height: 50px; padding: 6px 12px; font-size: 18p ...

Ways to execute a function upon form submission

On my HTML page, I have a section dedicated to receiving a threshold value and calling a function with that value. <form id="distance_input" onSubmit="return false;" > <p>Enter a threshold</p> <div class="col-md-8" style=" ...

The folder path of the Nodes Express App.Route is causing confusion for other users

When utilizing Nodes.js Express for my routing, I encountered an issue. Normally, localhost:8080/Order works fine. However, when trying to use the GET method with the ID parameter like localhost:8080/Order/ID-12345 and proceeding to ViewOrder.html to execu ...

Ways to avoid grid overflow

As a newcomer to CSS grid, I am struggling to understand how to prevent components from overflowing a grid. The section in question, with the class name of profile-widget-wrapper, is defined with grid-row:2/4 but is overflowing the grid. Can anyone provide ...

Create a stylish frame for designated rows within a table

Col1 Col2 Col3 Col4 Col5 Col6 Row11 Row12 Row13 Row14 Row15 Row16 Row21 Row22 Row23 Row24 Row25 Row26 Row31 Row32 Row33 Row34 Row35 Row36 Looking for a way to add a border around rows with matching values in the first column, or around a specif ...

The animation unexpectedly resets to 0 just before it begins

Currently, I am developing a coverflow image slider with jQuery animate. However, there are two issues that I am facing. Firstly, when the animation runs for the first time, it starts at `0` instead of `-500`. Secondly, after reaching the end and looping b ...