Having trouble with the functionality of the cascading menu?

I am having trouble with a drop-down menu. The first level works fine, but I can't seem to get the second level of the menu to display. Appreciate any help you can offer. Thank you.

javascript

<script type="text/javascript">
$(document).ready(function () {
$('#nav li').hover(
function () {
//show submenu
$('ul', this).css({zIndex:90}).fadeIn(150);
},
function () {
//hide submenu
$('ul', this).fadeOut(150);

}
);

HTML

<input type="hidden" name="arav" /><ul id="nav">
<li> <a href="index2.html">Home</a>
</li>
<li> <a href="personnel.html">Who We Are</a>
</li>
<li> <a href="#">Neurologic Condition</a>
<ul>
<li><a href="sci.html">SCI</a></li>
<li><a href="tbi.html">TBI</a></li>
<li><a href="stroke.html">Other</a></li>
</ul>
</li>
<li> <a href="">Education</a>
<ul>
<li><a href="healthed.html">Health Education</a></li>
<li><a href="#"> Materials</a>
<ul>Videos
<li>Videos</li>
<li>Presentation</li>
<li>Movies</li>
</ul>

</li>

<li><a href="sciinfosheets.html">SCI Info Sheets</a></li>
</ul>
</li>
<li> <a href="stroke.html">Resources</a>
<ul>
<li><a href="statelevel.html">State Level</a></li>
<li><a href="nationallevel.html">National Level</a></li>
<li><a href="resourcesbycoutny2.html">Community Level</a></li>
</ul>
</li>

<li> <a href="research.html">Research</a></li>

<li> <a href="contactus.html">Contact Us</a>
</li>
</ul>

CSS

#nav {
margin:0;
padding:0;
list-style:none;
behavior: url(border-radius.htc);

}

/*LI display inline */
#nav li {
float:left;
display:block;
width:7em;
background:#0063dc;
position:relative;
z-index:500;
margin:0 1px;
}

/*parent menu*/
#nav li a {
display:block;
padding:5px 5px 5px 5px;
font-weight:700;
height:38px;
text-decoration:none;
color:#696969;
text-align:center;
color:#ffeecc;
}

#nav li a:hover
{
color:#eeeeee;
}

/* style for default selected value */ #nav a.selected {
color:#6699FF;
}
/* submenu */ #nav ul
{
position:absolute;
left:0;
display:none;
margin:0 0 0 -1px;
padding:0;
list-style:none;
}

#nav ul li
{
width:7em;
float:left;
overflow:hidden;
border-top:1px solid #eeeeee;
}

#nav ul a
{
display:block;
height:32px;
padding: 7px 4px;
color:white;
}

#nav ul a:hover
{
text-decoration:none;
}

Answer №1

After some cleaning up, the issue with the tertiary menu not displaying was identified as #nav ul li having overflow:hidden set, which was causing the menu to remain hidden. Removing this setting resolved the problem. I also made some adjustments to the JavaScript in the example below.

Check out the demo here: jsfiddle.net/Marcel/kydTs

Answer №2

It seems like there may be an issue with the HTML code:

<li><a href="#"> Content</a>
<ul>Images                 // This part is not considered valid
<li>Images</li>

This portion of the HTML is not properly formed.

Could you provide a link to an online example?

Update: I have included a sample in here.

One problem I noticed right away is your utilization of #nav ul li { overflow: hidden }. This rule indicates that anything exceeding the boundaries of your li (such as the sub-sub menus) will remain hidden. Additionally, you will need to incorporate some positioning for the lowest-level menus.

Answer №3

Aside from the HTML mistake mentioned earlier, the CSS is also incomplete. All child lists are positioned to the left, causing them to overlap, and the child li elements have overflow hidden, hiding their children as well.

The jQuery code is slightly incorrect as well; it will hide all child li elements as soon as the first list is hovered on. Presumably, you only want them to appear when their immediate parent is hovered on?

Revised CSS:

#nav {
margin:0;
padding:0;
list-style:none;
behavior: url(border-radius.htc);
}

#nav {width: 100%;}
#nav ul, #nav li {width: 7em;}

/* LI display inline */
#nav li {
float:left;
background:#0063dc;
position:relative;
z-index:500;
margin:0 1px;
text-align:center;
}

/* Parent menu */
#nav li a {
display:block;
padding:5px 5px 5px 5px;
font-weight:700;
height:38px;
text-decoration:none;
color:#ffeecc;
}

#nav li a:hover {
color:#eeeeee;
}

/* Style for default selected value */
#nav a.selected {
color:#6699FF;
}
/* Submenu */
#nav ul {
position:absolute;
display:none;
margin:0 0 0 -1px;
padding:0;
list-style:none;
}

#nav ul {left: 0;}
#nav ul ul {left: 100%; top: 0;}

#nav ul li {
/*overflow:hidden;*/
border-top:1px solid #eeeeee;
}

#nav ul li:hover {position: relative;}

#nav ul a {
display:block;
height:32px;
padding: 7px 4px;
color:white;
}

#nav ul a:hover {
text-decoration:none;
}

Revised script:

<script type="text/javascript>
$(document).ready(function() {

    $("#nav li").hover(
        function () {
        $(this).children("ul").fadeIn(250);
        },function(){
        $(this).children("ul").fadeOut(250);
    }); // hover

}); // document ready
</script>

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

Failing to retrieve data from Ajax response

When handling requests in a servlet, the following code snippet processes the request received: Gson gson = new Gson(); JsonObject myObj = new JsonObject(); LoginBean loginInfo = getInfo(userId,userPwd); JsonElement loginObj = gson.toJsonTree(loginInfo) ...

Perform an action in jQuery when a class is modified

I am trying to create an event that will trigger when a specific element receives a class, and also when that class is removed. For example: <button id="my_butt_show">showtime</button> <button id="my_butt_hide">hide me</button> &l ...

What is the best way to retrieve the element at the current cursor position inside an iframe

I'm currently working on a script that is intended to retrieve the element positioned at the cursor's location within an iframe. The code I am attempting to implement should be able to identify the deepest child element at the cursor's posit ...

Error encountered: Parsing error in Typescript eslint - The use of the keyword 'import' is restricted

My CDK application is written in typescript. Running npm run eslint locally shows no errors. However, when the same command is executed in a GitLab pipeline, I encounter the following error: 1:1 error Parsing error: The keyword 'import' is r ...

Error: cannot use .json data with `filter` method from WEBPACK_IMPORTED_MODULE_2__["filter"]

There seems to be an error occurring when attempting to retrieve data from a JSON file in the specific line of code selectedEmployee: employeeList.data.Table[0], An issue is arising with TypeError: _employeeList_json__WEBPACK_IMPORTED_MODULE_2__.filter ...

What is the best way to ensure an image fills the entire space within a Bootstrap modal container?

I'm having some issues with my bootstrap modals that contain images. When the images are long vertically, a scrollbar appears which is not ideal. I tried to solve this by setting a max-height for the modal-content and making the modal-body (where the ...

Rect cannot be resized using mouse events

I am currently working on resizing the rectangle inside the SVG using mouse events. To achieve this, I have created another circle shape at the right bottom edge of the rectangle and implemented resize events on that shape. However, I'm facing an issu ...

Tips for serving a JSON text file to a client-side AJAX request from a Node.js server

I have a node.js web app running on an AWS Ubuntu server. The json data from an API is stored locally on the server in a file named data.json. My goal is to load this data via AJAX and display it on the client-side HTML. Below is my project directory str ...

Positioning the HTML form in the middle of the page

The given HTML code generates a form within a table, but despite aligning the table to the center, it remains on the left side of the webpage. <!DOCTYPE html> <html> <head> <style>input.textfill { float: right; }&l ...

Numerous Radio Buttons

I am currently working on creating a quiz similar to those found on Buzzfeed and Zimbio. I apologize if this question has been asked before, but despite my efforts in searching, I have not been able to find the answer I am looking for. In this quiz, partic ...

Combine all the HTML, JavaScript, and CSS files into a single index.html file

So here's the situation - I am utilizing a C# console application to convert four XML files into an HTML document. This particular document will be circulated among a specific group of individuals and is not intended to be hosted or used as a web app; ...

What is the reason behind Gmail altering the id attributes of certain elements?

Here we have a snippet from Gmail, showcasing the "Compose" button. Note the id, it starts as ":il" when there are no unread messages. <div id=":il" class="aic"> <div class="z0"> <div class="T-I J-J5-Ji T-I-KE L3" tabindex="0" role="button" ...

Attempting to modify a JSON file within a React application

I recently obtained a JSON file named 'DealerList.json' which I managed to import into my app using the following code snippet: import DealerList from './json/DealerList' let tasks = DealerList; The tasks now store the JSON data and I ...

Ways to modify the color of mat-icon within an input field using Angular 6

Here is the code from my HTML file: <div class="input-field"> <div> <input type="text" id="name" required email/> <label for="name">Email: <mat-icon svgIcon="mail" class="change-color"></mat-icon> &l ...

The animation-play-state is set to 'running', however, it refuses to start playing

I'm in the process of creating a landing page that includes CSS animations, such as fade-ins. Initially setting animation-play-state: "paused" in the CSS file, I later use jQuery to trigger the animation while scrolling through the page. While this s ...

Programmatically Expand and Collapse All nodes in MUI DataGrid using ReactJS

Is there a way to programmatically expand or collapse all rows in MUI ReactJS DataGrid? What have I tried? I attempted to use the defaultGroupingExpansionDepth property as suggested in the MUI documentation: export const EXPAND_ALL = -1; export const COLL ...

What is the correct method for iterating through this array of objects and eliminating those with either null or empty item.text values?

Currently, I am working with the following Array: const contactInfo = computed(() => { return [ { id: 'address', icon: 'detail/clubLocation', text: `${props.data.contactInfo.address}` ...

Creating a Kendo Menu within an Ext JS Panel

Currently, I am experimenting with combining ExtJS and Kendo UI - a unique mix that is taking me off the usual path ;) I have managed to render a Kendo Menu onto an Ext JS (4.2.1) generated Ext.form.Panel In case you want to check it out, here's a F ...

HTML background image not displaying in JSPDF addHTML function

I am facing an issue with my HTML page where the background image in the header section is not displaying when converting the page to PDF using jspdf. Although all the other content appears correctly, the background image seems to be missing. You can vie ...

My array magically transforms into an object once it reaches 22 elements, why is that happening? (node)

While working on a form with multiple checkboxes that have the same name and submitting it through a node/express post route, I encountered an issue. Here is the corresponding HTML code: https://pastebin.com/xeQae6GA The problem arises when trying to ret ...