How can the bootstrap mega menu be modified to use an onclick function and incorporate drop-down items for mobile users?

Is it possible to change the drop-down menu behavior for small devices to make it work on click instead of hover? The issue I'm facing is that the sub-menus are appearing outside the root navigation on mobile devices. How can I modify the code to ensure the drop-down menu subs appear inside the root nav and function on click for mobile?

You can find the source code from here

Modified HTML:

<body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="container">
		...
		     
// Dropdown Menu Fade    
jQuery(document).ready(function(){
    $(".dropdown ").hover(
        function() { $('.dropdown-menu', this).stop().fadeIn("fast ");
        },
        function() { $('.dropdown-menu', this).stop().fadeOut("fast ");
    });
});
    </script>
</body>

CSS:

.navbar-brand {
    padding: 0px;
}
...
@media (max-width: 768px) {
    .navbar-default .navbar-nav > li > a {
	...
	.navbar-collapse.collapse {
	...
	
	my code on:  <a href="http://jsfiddle.net/jaman7/6wbvk8ed/2/" rel="nofollow">Check this updated code on FIDDLE</a></p>

Answer №1

To make some adjustments to your website's appearance, you'll need to modify the CSS code.

.navbar-default .navbar-nav > .open > a{
  background : transparent !important;
 }

.navbar-nav .open .dropdown-menu{
  background : white;
}
.navbar-nav .open .dropdown-menu .dropdown-header{
  color : #999999 !important;
}

Check out the latest version on jsFiddle

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

Get an ICS file as text using JQuery

As a newcomer to JQuery and JS, I seek your understanding for any mistakes I may make. My current goal is to extract the text from an ICS file (e.g. BEGIN:CALENDAR....) using JavaScript. Here is a simple HTML file I am working with: <html> <b ...

Selenium web scraping falls short in fully extracting all the data needed

Struggling to extract bond information from a webpage using Selenium. Despite successfully retrieving data for some rows in the table, certain rows and columns remain unscraped. The reason behind this inconsistency is unclear. The target webpage can be fo ...

Navigating ngMessages in Angular - Retrieving Data from Multiple Form Fields

Struggling to implement a custom validation function in Angular's ngMessages. My goal is to ensure that the total of two input values always amounts to 100. I've crafted a new directive named totalOneHundred, set to trigger on form changes. How ...

Error: the function is not defined, therefore the variable is being passed

I'm attempting to pass a variable in the URL in order to automatically check a radio button on a different page depending on which link is clicked. However, I keep encountering an "Uncaught ReferenceError: radio_onload is not defined" error. Could th ...

Oops! There was a validation error as the duration was not formatted as a number. Please make sure to provide a valid numerical value for the duration field

When attempting to update data from a MongoDB database and checking the results on Postman, an error is encountered. The error reads as follows: "Error: ValidationError: duration: Cast to Number failed for value \"NaN\" at path \"duration&bs ...

Retrieving the headers from an ajax request

Is there a method to retrieve the complete request headers used in an AJAX call made through jQuery? ...

What could be causing my BXSlider to malfunction?

Issue My BXSlider is not showing up on the page. It just displays a blank page. I have double-checked my page structure and everything seems to be in order. Expected Appearance HTML Code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

Identifying the presence of a mouse inside an element using jQuery

I am working on a website that utilizes jQuery. The structure of my page is as follows: <div id="page"> <!-- Content goes here --> <div id="content"> <div class="row"> <div class="col"><!-- content goes here ...

Tips for positioning a div with z-index to cover another div when hovering

I'm working on a container div that contains multiple smaller div elements, all with the style rule float:left;. When I hover over one of the smaller div elements, I want it to increase in height and width while overlaying the other div elements witho ...

Clickable boxes for selecting options (Ajax and JavaScript)

I have a new project that involves creating a checkbox and using ajax and javascript to change its state when clicked. The goal is for the checkbox state to be saved in a php program that generates a .txt file. The state should be 0 when not clicked and 1 ...

Tips for removing cookies with Javascript after an allotted period of time

I need to remove a specific cookie value that I set after a certain time period. For example, I want the cookie to be deleted after 10 seconds. function fullday() { document.getElementById("res").innerHTML="1 day"; document.cookie="day="+1; do ...

Generate a dropdown list in real-time by pulling text from a text area

I prefer to have this coded in jquery, but I am also okay with javascript. Here is the question: I have a textarea and a dropdown menu on the same page. I can input text into the textarea by typing or pasting it. Each line in the textarea contains email ...

Retrieve the date from 7 days ago and display it in the format "2015-06-23" using JQuery/JavaScript

Looking to retrieve last week's date in the following format: "2015-06-23", as opposed to "2015-06-16". JavaScript: t = new Date(); // Tue Jun 23 2015 21:00:47 GMT-0700 (PDT) t.toISOString(); // "2015-06-24T04:00:47.955Z" The current date format i ...

Retrieving PHP variables within the HTML document of the current page

Suppose I have a page with a link <a href='edit_info.php?id=1001'>1001</a>. In the edit_info.php page, I want to use this id to query a database, like so: SELECT * FROM table WHERE id = $_GET['id'] Now, I need to populate ...

What causes compatibility issues between JEST and import statements in NEXTJS?

Just starting out with unit testing in JavaScript and I'm attempting to create a unit test for a Next JS project. However, when running the test, I encountered the following error: Code: import {isBase64} from '../../service/base64-service&a ...

Obtaining dynamically added control values from the $.ajax callback

Currently, I am developing a master/details style grid using Ajax and JQuery. In the main grid, there is a one-liner with basic information and a "+" sign that can be clicked to expand the row. When expanded, the details are fetched using JSON technology w ...

What could be causing my state not to change in Nextjs even though I followed the quick start guide for Easy Peasy?

I recently encountered an issue while trying to implement easy peasy for global state management in my nextjs app. The problem I faced was that the state would only update when I changed pages, which seemed odd. To better understand what was going on, I de ...

Error message: "Angular dependencies and provider not accessible"

I recently came across a file upload script on Github that I decided to implement. <script type="text/javascript" src="{% static 'bower_components/angular-file-upload/angular-file-upload.min.js' %}"></script> Furthermore, I have cre ...

Calculating the hour difference between two time stamps (HH:MM:SS a) using moment.js

I have two time without date var startTime="12:16:59 am"; var endTime="06:12:07 pm"; I need to calculate the total hours between the above times using a library like moment.js. If it's not achievable with moment.js, then please provide a solution u ...

Issue with plain CSS animation not functioning in NextJS with Tailwind CSS

I found this amazing animation that I'm trying to implement from this link. After moving some of the animation code to Tailwind for a React Component, I noticed that it works perfectly in Storybook but fails to animate when running in next dev. It si ...