js Issues with the Drop Down Menu

I'm having trouble with creating a dropdown menu. When I hover over the page, it works fine, but if I hover over the link it doesn't work properly. In short, this drop-down list is behaving opposite to what I want. I need a fix or a better way to create this dropdown menu.

enter image description here

enter image description here

HTML

<body>
    <div class="wrap">
        <nav class="navbar navbar-default navbar-fixed-top navbarcolor  ">
            <div class="container ">
                <div class="navbar-header active">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                        <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 Brand-Color active " href="#">MediQ.ch</a>
                </div>
                <div id="navbar" class="navbar-collapse collapse">

                    <ul class="nav navbar-nav navbar-right">
                        <li><a class="navbar-R-C  " href="#">AdminStraion</a>
                        </li>

                        <li class="dropdown  sub-menu-parent">
                            <a id="drop" href="#" class="navbar-R-C nav-link dropdown-toggle " data-toggle="dropdown" aria-expanded="false">BookMarker
                  <span class="caret"></span></a>

                            <ul id="content" class="dropdown-menu " role="menu">
                                <li><a class="content " href="#">ACETILXSUBSTANCE2</a>
                                </li>
                                <li><a class="content " href="#">HIDROCORTIZOLXBENZTIL</a>
                                </li>
                                <li><a class="content " href="#">SUBSTANCE3XSUBSTANCE4</a>
                                </li>

                            </ul>
                        </li>

                        <li><a class="navbar-R-C " href="#">Contact</a>
                        </li>
                    </ul>

                </div>
                <!--/.nav-collapse -->
            </div>
        </nav>
    </div>



</body>

CSS

.navbar-R-C:hover {
    color: white !important;
}
.content {
    color: White !important;
}
.dropdown-menu {
    min-width: 250px;
    max-width: 250px;
    text-align: center;
    background-color: #3E606F;
    margin-top: -6px !important;
    color: white !important;
    border-radius: 15px !important;
}
.dropdown-menu > li > a:hover {
    text-align: center;
    background-color: #EC407A;
    font-weight: bold;
    margin-left: 7px !important;
    margin-right: 7px !important;
    display: inline-block;
    color: White;
    border-radius: 10px !important;
}
.dropdown-menu:after {
    position: absolute;
    margin-left: 210px;
    top: -6px;
    left: -30px;
    border-right: 10px solid transparent;
    border-bottom: 10px solid #3E606F;
    border-left: 10px solid transparent;
    content: '';
}
.dropdown:hover .dropdown-menu {
    display: block;
}

JavaScript

$(document).ready(function() {
    $('.wrap nav ul li').hover(function() {
        // Toggles slide but stops if not hovered anymore
        $(this).find('ul').stop().slideToggle();
        // Toggles on and off the active class (triangle)
        $(this).find('div').toggleClass('active');
    }
    );
}
);

Answer ā„–1

To achieve the desired look, you will need to override some CSS styles in Bootstrap that may be interfering with your code. Additionally, make sure to include the necessary Bootstrap.css, Bootstrap.js, and jQuery.js files. You can either load them directly from the web or download and link them for offline use.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 </head>
 <body>

    <nav class="navbar navbar-default navbar-fixed-top navbarcolor  ">
        <div class="container ">
            <div class="navbar-header active">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <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 Brand-Color active " href="#">MediQ.ch</a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">

                <ul class="nav navbar-nav navbar-right">
                    <li><a class="navbar-R-C  " href="#">AdminStraion</a>
                    </li>

                    <li class="dropdown  sub-menu-parent">
                        <a id="drop" href="#" class="navbar-R-C nav-link dropdown-toggle " data-toggle="dropdown" aria-expanded="false">BookMarker
              <span class="caret"></span></a>

                        <ul id="content" class="dropdown-menu " role="menu">
                            <li><a class="content " href="#">ACETILXSUBSTANCE2</a>
                            </li>
                            <li><a class="content " href="#">HIDROCORTIZOLXBENZTIL</a>
                            </li>
                            <li><a class="content " href="#">SUBSTANCE3XSUBSTANCE4</a>
                            </li>

                        </ul>
                    </li>

                    <li><a class="navbar-R-C " href="#">Contact</a>
                    </li>
                </ul>

            </div>
            <!--/.nav-collapse -->
        </div>
    </nav>  
    <div class="container">
      <h3>Navbar With Dropdown</h3>
      <p>This example adds a dropdown menu for the "Page 1" button in the navigation bar.</p>
    </div>

  </body>
</html>

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

Error alert: Index not defined!

I have a dropdown select that needs to be populated with values from a database. I then need to validate the selected value using a JavaScript function, which is already implemented. The dropdown list has two columns: one for ID identifiers and another fo ...

Trouble with achieving equal height columns in nested flexbox layout on Google Chrome

I am looking to evenly space several sidebar blocks throughout a lengthy post. To achieve this, I have utilized Flexbox within the sidebar for handling the even distribution of the blocks and it has been working flawlessly. Check out Code Pen: http://cod ...

JavaScript glitch preventing fancybox functionality in Firefox browser

I'm experiencing an issue with FancyBox not working on Firefox while using js no conflict on this specific site Upon inspecting with Firebug, I encountered the following error: Error Line: 99 A similar error is also being thrown by Safari: Typ ...

Animated Content Sliding out Smoothly from Right to Left Using jQuery

I am attempting to implement a slideout function from the right side using jQuery. I have tried modifying the code for "From Left to Right" but it doesn't seem to be working correctly. Can you please provide me with guidance on how to make the necessa ...

Unusual trio of divs lined up next to each other

I typically work with tables, but I need to rearrange some div elements by dragging and dropping them. I decided to try a table-less approach this time around. Here's my goal: I want the spacing between all elements to be 24px. My main issue is gett ...

The nodejs application seems to be encountering an issue as the /public/index.html file is not displaying on the

|project-name | client | public | index.html | server.js ā†‘ Structure of the Project The goal is to display the index.html file (located in the public folder) in server.js. [ server.js ] const express = require('express') const app ...

Rendering various models in separate DIVs using Threejs

(Brand new to venturing into Three.js) Overview Currently, I am immersed in the development of a 3D Viewer that can showcase multiple stl models simultaneously. Each model is supposed to be rendered within its own separate div element, resulting in a g ...

Utilizing the spread operator to map an array within another array

Exploring the spread operator inside an array to map values from another array has led to unexpected behavior. When attempting to return 2 objects using map within the array, only the last object is being returned. Below is the code snippet: const cats = [ ...

I am facing an issue with Angular where the $http.get method is

It seems like there must be a small oversight causing this apparently simple problem. I have a function that interacts with the Spotify API to search for an artist. I know that by accessing the corresponding route using a standard URL, a result is returne ...

Arranging Fancybox images into categories

I am currently experimenting with the fancybox function. It seems to be working fine, but for some reason it is not grouping up based on my Rel attribute. Below is the JavaScript code: <script type="text/javascript"> $(function($){ var ...

How can I target an element with inline styling using CSS?

How can I target headings with inline style 'text-align: center' in my CSS so that I can add ::after styling to them? This is for a WordPress CMS, specifically to modify content in the WYSIWYG editor used by clients. Here's an example of th ...

What sets server-side development apart from API creation?

As I dive into the world of web development, I find myself facing some confusion in my course material. The instructor has introduced concepts like promise objects and fetch, followed by axios, and now we're delving into the "express" package for buil ...

Utilizing PHP to retrieve and insert data from a database, then display the information within a div. Despite CSS being configured with different width and height settings, the div expands accordingly

I am currently utilizing PHP to input information into a database and then use that information in a simple comment system. Being new to PHP, I am unsure if there is an easier way to achieve what I am doing. However, I am facing a challenge where if the in ...

Obtaining the identifier of a list element from an external HTML document utilizing jQuery through AJAX

I have a separate HTML file that only consists of an unordered list with several list elements listed below: <ul> <li id="list-1"></li> <li id="list-2"></li> <li id="list-3"></li> <li id="list-4 ...

Create a line connecting two divs using jQuery's DOM manipulation capabilities

Looking to connect two divs with a straight line, I stumbled upon jQuery DOM line, which appears to offer a more streamlined solution compared to jsPlump. I attempted to incorporate it into my code, but unfortunately, it's not working as expected. Be ...

What are the possible reasons for the failure of JavaScript when called dynamically through Ajax?

I've always been a big supporter of the JavaScript code for sorting tables. It's incredibly effective. However, I recently encountered an issue while trying to make the sorting function work with Ajax. I have a div layer on my main page that fe ...

Only wrap certain elements if they consist of two specific items

<div class="section"> <label>Title: </label> <input type="text" /> </div> <div class="section"> <label>Text: </label> </div> My goal is to enclose the label + input within an additional div ...

JavaScript sorting code fails to properly sort numbers

Here is a code snippet that aims to convert a string into an array of numbers and then sort them in descending order. The objective is to find an alternative to the sort() method. However, there seems to be an issue with the current implementation. When t ...

Striving to convert Celsius to Fahrenheit using ReactJS

I am currently attempting to convert Celsius into Fahrenheit within this specific div. Despite being fairly new to React, Iā€™m finding it challenging to determine where exactly to place the conversion calculation. return ( <div className="app& ...

Chrome displays the page layout differently upon initial loading

https://i.sstatic.net/GhfJc.pngI am currently seeking a developer position and have created a personal website to showcase my skills to potential employers. However, I have encountered a bug that only seems to affect Chrome browser. When the page is first ...