Show a nested outline when hovering over the main list item

I have a structured menu with nested lists for sub menus

<nav>
<ul>
<li class="itm">A
    <ul>
        <li>One</li>
        <li>Two
            <ul>
                <li>Menu Item 1</li>
                <li> Menu Item 2 </li>
                <li> Menu Item 3 </li>
            </ul>
        </li>
        <li> Three </li>
        <li> Four </li>
    </ul>
</li>

<li class="icon"><span class="img"></span></li>
<li class="itm">B</li>
<li class="itm">C</li>
</ul>
</nav>

When hovering over a parent li, I want to display the corresponding sub menu. This is how I'm trying to achieve it:

$('nav ul li').hover(function () {
    console.log(this);
    $(this).find('ul').fadeIn();
}, function () {
    $(this).find('ul').fadeOut();
});

However, when hovering, I encounter this error in the JS Console:

Uncaught ReferenceError: ul is not defined

Answer №1

The issue with your selector is the combination of this, a literal, and what should be a string in the selector (> ul). You are treating ul as a variable when it doesn't exist.

To resolve this problem, try the following:

http://jsfiddle.net/cyzsw/

$(this).children('ul').fadeIn();

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

What is the best way to implement async/await at the top level of my code?

After researching extensively on async/await, I decided to experiment myself. However, I am struggling to understand why the following code snippet does not work as expected: async function main() { var value = await Promise.resolve('Hey there&a ...

Issues with MVC4 JSON Model Binding are causing problems

We have created a Viewmodel named GetUsersFromNextCircuitRequest, which includes the following properties: public class GetUsersFromNextCircuitRequest { public int? dosarId { get; set; } public List<int> dosareIds { get; set; } ...

How do you manage dependencies for nested components within Angular2?

Encountering an Issue: browser_adapter.js:76 Error: Cannot resolve all parameters for NestedComponent(undefined). Make sure they all have valid type or annotations. at NoAnnotationError.BaseException [as constructor] Diving Deeper Into the Problem: ...

Ways to align my image to the left and text to the right using Bootstrap

body{ height: 100%; font-size: 1rem ; } .navbar-brand{ font-family: 'Syne Mono', monospace; color: black; size: 0.5rem; } header { width: 100%; height: 100vh; background: rgb(237,104,104); background: linear-gradient(90d ...

Build dynamic dropdown menus in Angular.js using cookie data

I'm facing an issue with populating a three-tier dependent dropdown in Angular with saved cookies. Sometimes, all three tiers populate correctly, but other times they show as blank strings or only partially populated. Upon inspecting the HTML code, I ...

How to Programmatically Assign Bootstrap Class to an Element Using Angular 2

I am working on a page with several input boxes that need to be flagged for certain criteria. <div class="form-group"> <label class="d-block">Allowance Type</label> <div class="input-group"> ...

Is there a way to simulate the parameters of a method callback from an external dependency in Nodejs

Imagine a scenario where I have the following structure: lib/modules/module1.js var m2 = require('module2'); module.exports = function(){ return { // ... get: function(cb){ m2.someMethod(params, function(error, ...

Implementing dynamic CSS in AngularJS using conditional statements

One technique I've been using in angularjs involves toggling between two windows using the ng-click and ng-show directives: <div ng-init="showTab2 = false"> <a ng-click="showTab2 = true; showTab1 = false ">#Tab1 </a> ...

Deleting all items is not possible if the "select all" checkbox is checked

After checking the topmost checkbox, my code is supposed to check all checkboxes and then delete all checked checkboxes when I click on the 'delete all' button. However, I am facing an issue where I am unable to delete the checked boxes. I need ...

Tips on displaying JSON data in the browser console using console.log for API consumption

I'm having trouble creating an api to output data parsed from an xml file. When I console.log the necessary data, it shows up fine, but when I try to display it in the browser, I only get an empty array. Any suggestions on what could be causing this i ...

An advanced template system incorporating dynamic scope compilation

My project requires a unique solution that cannot be achieved with standard data-binding methods. I have integrated a leaflet map that I need to bind with a vue view-model. While I was able to display geojson features linked to my view, I am facing chall ...

Tips for utilizing Selenium to acquire links from a webpage

Is it possible to retrieve the link location of a web element in Selenium? While we can easily obtain the text from a web element and use getAttribute("href") method to get the location of a hyperlink, my need is to extract all the links present. For insta ...

Finding the chosen selection in AngularJs

I've been working on this script for hours and I'm struggling to output the text instead of the value of a select option in AngularJS in HTML through data binding. Despite my efforts, I keep getting the value instead of the text. How can I resolv ...

Creating an array of objects through checkbox validation in AngularJS

$scope.data = [{ 'id': '1', 'itemName': 'mousepad', 'price': '20' }, { 'id': '2', 'itemName': &apo ...

Mastering form submission with Node.js and enhancing it with JQueryMobile

I'm currently working on a project that involves using node.js and jQuery Mobile, but I've encountered some issues with managing the form submission. Can anyone provide guidance on how to navigate to the next page? What parameters should be passe ...

What is the best way to line up a number and text using CSS?

Creating a basic gauge meter with min value 0 and max value 2. The current UI progress is as follows: .sc-gauge { width:200px; height:200px; margin:200px auto; } .sc-background { position:relative; height:100px; margin-bottom:10px; background-color:g ...

Animate elements in Vue.js when navigating between pages is a great way to enhance user

I'm looking to add animation to a specific element once the route page finishes loading. This is not related to route page transitions. I've experimented with various methods, trying to animate a progress bar based on dynamic data values. I attem ...

What could be causing the border-collapse property to be ineffective on my HTML table?

My HTML table has nested tables, but the border collapse property is not working. Despite adding the border-collapse property to both the main table and nested tables, only the outer borders are visible, with no inside borders. <table style="bord ...

MUI version 5 - Checkboxes are receiving a variety of unique classes

After recently upgrading from Mui v4 to v5, I've noticed a strange behavior with checkboxes. Upon inspecting the DOM differences between the two versions, it appears that some additional classes are now being applied in v5 and the extra span with the ...

Explore search results that include values nested within map arrays

I have an array with multiple objects, each containing a nested array of subValues. My goal is to filter components based on search criteria. While I can successfully search the parent level objects' values, I am struggling with filtering based on the ...