Designing hover-activated submenus and ensuring they appear at the forefront

I am currently utilizing jquery to implement a dropdown submenu on hover action.

Here is the structure of the code:

<div id="menucontainer">
  <ul id = "topmenu">
    <li><a onmouseover="javascript:show('div_1');">menu_1</a></li>
    <li><a onmouseover="javascript:show('div_2');">menu_2</a></li>
    <li><a onmouseover="javascript:show('div_3');">menu_3</a></li> # using onmouseover since generated from templates

  </ul>
  <div id="div_1" class="submenu">
    <ul>
      <li> submenu_1 </li>
      <li> submenu_2 </li>
      <li> submenu_3 </li>
    </ul>
  </div>
  <div id="div_3" class="submenu">
    <ul>
      <li> submenu_1 </li>
      <li> submenu_2 </li>
      <li> submenu_3 </li>
    </ul>
  </div>
  <div id="div_3" class="submenu">
    <ul>
      <li> submenu_1 </li>
      <li> submenu_2 </li>
      <li> submenu_3 </li>
    </ul>
  </div>
</div>
<style>
#topmenu {
  list-style: none;
}
#topmenu > li {
  display: inline-block;
}
.submenu {
  display: none;
}

<script>
function show(divid) {
  $('.submenu').css('display', 'none');
  $('#'+divid).css('display', 'block');
}
</script>

An issue arises when show(div) function is triggered and the submenu div appears, there is another div positioned after "menucontainer" that obstructs clicks on the displayed div. How can this problem be resolved?

Answer №1

Your HTML code has been restructured for simplicity, and event listeners are now recommended over inline function calls. Feel free to reach out if any part of this modification doesn't suit your needs.

Explore the updated code on JSFiddle

<div id="menucontainer">
    <ul id="topmenu">
        <li><a href="#">menu_1</a></li>
        <li><a href="#">menu_2</a></li>
        <li><a href="#">menu_3</a></li>
    </ul>
    <div id="div_1" class="submenu">
        <ul>
            <li>submenu_1</li>
            <li>submenu_1</li>
            <li>submenu_1</li>
        </ul>
    </div>
    <div id="div_2" class="submenu">
        <ul>
            <li>submenu_2</li>
            <li>submenu_2</li>
            <li>submenu_2</li>
        </ul>
    </div>
    <div id="div_3" class="submenu">
        <ul>
            <li>submenu_3</li>
            <li>submenu_3</li>
            <li>submenu_3</li>
        </ul>
    </div>
</div>

$('#topmenu li a').hover(function () {
    var myItem = $(this).parents('li').index() + 1;
    $('#div_' + myItem).slideDown();
}, function () {
    $('.submenu').hide();
});

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

Verifying credentials using Chromium pop-up window with Playwright

In my current project, I am using Playwright to automate the configuration of multiple devices. However, I have encountered a challenge with certain models that require authentication through a popup dialog box in Chrome. https://i.stack.imgur.com/jgnYM.p ...

Simple Way to Modify Color of Active Page Link - HTML, CSS, and JavaScript

I found a helpful example on how to change link colors for the current page here. Here is the script I added: <script> // current page highlight $(document).ready(function() { $("[href]").each(function() { if (this.href == window.l ...

Dynamic flexibility for content scrolling across components

Creating a mobile-friendly terms of service page with a title, content, and two buttons is my current project. The specific requirements are: All components should not exceed 100% of the viewport to allow for scrolling The buttons need to stay sticky at t ...

Displaying an error or success message upon submitting a form is currently not functioning as

I have implemented a registration/login system on my website, and currently, it shows errors and success messages at the top of the page. I want to display these messages under the form instead. However, every time I attempt to place them below the form, i ...

Tips on making a material-ui grid fill up the entire screen

Currently, I am working on developing a layout that resembles most editor/IDE setups using material-ui and react. In this layout, I have a top bar, a bottom bar, side panels on both sides, and a center area. My main concern is how to ensure that this grid ...

Issue with JavaScript code for Google Maps API not functioning as expected

Can someone help me troubleshoot why my simple Google Maps setup isn't working? Thanks! HTML <script defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBy2rXc1YewdnqhPaaEd7H0I4DTV_pc7fo&"> </script> <div id="map"> & ...

Tips on enhancing the appearance of your numberbox with vibrant colors

Hello everyone! I am working with some devextreme code blocks and need help in changing the border color of a numberbox to red. Can anyone guide me on how to achieve this? import React, { useState } from 'react'; import { NumberBox } from 'd ...

Aligning the stars with CSS

One of the components I have deals with a star rating system, and I thought it would be cool to use Font Awesome icons for half stars. Everything is working well except for the CSS styling aspect. While I managed to position some of the stars correctly by ...

Utilize the input field value in an HTML dialog box to assign it to a variable in the code.gs file with the help

I'm trying to create a dialog box where the user can select a year, and then have the server process the selected value using the function doSomethingWithCompetitionYear(theYear). I've researched several discussions, but I'm having trouble ...

Extract value from child div using JQuery and update text in another section of the page

Here is a fiddle showcasing the concept I am working on: https://jsfiddle.net/wvz9p3e7/1/ The code is written in PHP and involves a loop for cycling through 7 or 8 different garments. My goal is to have the window on the right side of the fiddle display t ...

What is the best way to verify the success of two ajax requests?

There are two ajax requests being made to check the availability of two images. Below is the code for these ajax calls: if (result['img_one'] !== '') { var src_one = "blah-blah-one.jpg"; $.ajax({url: src_one, success: ...

I have just started a new project in Vue and noticed that the app div has some extra margin around it. Can anyone

In my fresh Vue project, I have the following code: App.vue: <template> <div id="app"> <p>hello</p> </div> </template> <script> export default { name: 'App', components: { } ...

werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The server is unable to process the request sent by the browser or proxy. This error occurred in a Flask web application

Can someone guide me on troubleshooting this issue in Flask? I am still learning. Server running at (Press CTRL+C to exit) 127.0.0.1 - - [26/Jul/2020 11:19:45] "GET /predict HTTP/1.1" 500 - Traceback (most recent call last): raise exceptions. ...

Navigate to a different URL following a post request using AJAX and EXPRESS

Currently, I am diving into the world of node.js servers by creating a login website. Users can input their username, which is then sent via an ajax post request to the server and stored in an array of all users. My goal is to redirect users to a personali ...

Place a written message on an picture

<head> <style> .relative{position:relative; width:600px;} .absolute-text{position:absolute; bottom:1; font-size:12px; font-family:"vedana"; background:rgba(251,251,251,0.5); padding:10px 20px; width:10%; text-align:center;} </style> < ...

Set a variable to represent a color for the background styling in CSS

My goal is to create an application that allows users to change the background color of a button and then copy the CSS code with the new background color from the <style> tags. To achieve this, I am utilizing a color picker tool from . I believe I ...

Utilizing AngularJS to selectively filter objects based on specific fields using the OR operator

My collection includes various items with different attributes. For instance, here is the information for one item: {"id":7,"name":"ItemName","status":"Active","statusFrom":"2016-01-04T00:00:00","development":"Started","devStartedFrom":"2016-01-04T00:00:0 ...

Options for jquery UI autocomplete only appear after the second search

Here is the code snippet I am working with: $("#hifind-find").keyup(function(){ var val = $(this).val(); if (val.length > 1) { var posturl = '/hifind/jquery_ui/autocomplete/'+val; $.post(posturl, function(r) { $("#hifin ...

Tips for Minimizing DIV Space with the Flex Property

I need some help with reducing the space between the individual content (1, 2, 3, 4) and its border in this Fiddle. As a newcomer to Flexbox, I'm unsure if there's an easy solution to this issue. Here is a visual representation of what I mean: ...

Accessing PHP parameters in JSP files can be accomplished by utilizing specific

The PHP code snippet below checks for a username and password match before redirecting to a JSP page. if($userName==$dbUserName&&md5($passWord)==$dbPassWord){ echo "<input name='username' type='hidden' value='$userN ...