Navigating multi-level drop-down menus on touch devices can be tricky, but there are ways to effectively

I recently created a website using HTML and CSS with a three-level navigation menu that worked perfectly on desktop. However, the issue arises when users access the site from touch devices like smartphones or tablets because the sub-menu does not appear when they tap on the parent menu item due to the lack of a cursor for hovering.

Can anyone suggest a solution to this problem?

Below is the code snippet for the menu:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<meta charset="utf-8">
<meta name="author" content="John Doe">
<style>
/* CSS styles here */
</style>
</head>
<body>

<h1>Navigation Menu</h1>

<ul id="navmenu">
  <li><a href="#">Hyperlink 1</a></li>
  <li><a href="#">Hyperlink 2</a>
    <ul class="sub1">
      <li><a href="#">Sublink 2.1</a></li>
      <li><a href="#">Sublink 2.2</a></li>
      <li><a href="#">Sublink 2.3</a></li>
    </ul>
  </li>
  <li><a href="#">Hyperlink 3</a></li>
  <li><a href="#">Hyperlink 4</a>
    <ul class="sub1">
      <li><a href="#">Sublink 4.1</a></li>
      <li><a href="#">Sublink 4.2</a></li>
      <li><a href="#">Sublink 4.3</a>
        <ul class="sub2">
          <li><a href="#">Sublink 4.3.1</a></li>
          <li><a href="#">Sublink 4.3.2</a></li>
          <li><a href="#">Sublink 4.3.3</a></li>
        </ul>
      </li>
    </ul>
  </li>
  <li><a href="#">Hyperlink 5</a></li>
</ul>

</body>

Answer №1

Hover functionality not supported on Touch devices.

To enable touch capability, you can utilize the Jquery Click event like so:

$("ul#navmenu li").click(function(){
    $('.sub1').removeClass('display');
    $(this).find('.sub1').addClass('display');
})

DEMO, Complete Code

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

Just for laughs: "The react-redux context value seems to be playing hide and seek; make sure to wrap the component in a <Provider> for it to show up!"

I encountered an issue while attempting to run a basic Jest test on a form React component: ● <LoginForm /> › clicking the validate button › should display page title ...

Contact form malfunctions with problematic Ajax functionality

I am facing issues with my ajax contact form. When I try to submit the form, I receive a "Please fill in all fields" message even though all fields are filled out. Here is my current form code: <form method="get" action="mail.php"> <inp ...

How can I send a variable to a service using AngularJS?

I am currently working on developing an app for movie tracking, and I am fairly new to Angular. I am facing a challenge in passing a variable to this service. Instead of hardcoding the URL, I want it to be a variable. What is the best approach to achieve ...

Creating a JSON data structure from HTML markup

My goal is to generate a json object by extracting data from a specific section of a wiki page (link). In the "Contents" section, I aim to gather all the information and structure it into an object as follows: { Arts : { "Performing Arts" : [{"Music" : [ ...

Animating CSS styles in Vue.js based on JavaScript triggers

Within my Vue.js application, I've implemented a login form that I'd like to shake whenever a login attempt fails. Though I have achieved the desired shaking effect, I'm not completely satisfied with my current solution. Here's a simpl ...

Retrieve a specific choice from a radio button and store it in a MySQL database

I need assistance with extracting the value from a selected radio button and inserting it into MySQL database. Although I have tried using isset(), I am facing issues when trying to retrieve the chosen radio button. Could someone please lend a hand? < ...

When the NPM package is imported as a whole, it shows up as undefined. However, when it

I've come across a peculiar issue in my code where importing the textile/hub package in Node.js and then destructuring it later results in an error. However, if I destructure it while importing, the program runs without any issues. Can anyone shed som ...

It is not possible to access fields in Firestore using Node.js

Exploring the limits of my Firestore database access with a test function: exports.testfunction = functions.https.onRequest(async (request, response) => { try{ const docRef = firestore.collection("Stocks").doc("Automobile" ...

What is the best way to modify properties in the DOM by accessing and changing the inline CSS style attribute with jQuery?

Need assistance with dynamically changing the document object model (DOM). Looking to access and manipulate the 'text-align' and 'line-height' properties. For instance: <p style="line-height:1.0;text-align:justify;"> Interested ...

There was an error thrown: Unable to access properties of an undefined value (specifically trying to read 'first')

Yesterday, my sister requested me to add a language change button to her website for some text. However, upon implementing it, I encountered the following error: Uncaught TypeError: Cannot read properties of undefined (reading 'first'). Despite t ...

Issue with deploying NEXT.JS due to a failure in the build process caused by next lint

Issue I have been encountering deployment failures on Vercel due to lint errors in test files within my git repository. Despite following the recommendations from the Vercel documentation for ESLint settings, the issue persists. According to Vercel' ...

Can you guide me on how to configure the system proxy settings on Windows operating system?

I'm working on developing a VPN application for Windows and I am interested in setting up a proxy on the system. While there are various methods to accomplish this (such as through the registry or command line), I am searching for a more efficient so ...

What is the best way to contain the CSS for dynamically generated HTML within a div element without impacting other elements on the page?

I am currently facing a challenge where users can input any HTML into a text box, and I need to manipulate that HTML by identifying elements such as anchor tags or divs. To achieve this, I have created a hidden div and copied the pasted HTML into it using ...

Is there a module loader in Angular.JS or do I have to rely on script tags for loading modules?

While using Angular JS, I have a desire to organize unrelated code in separate modules similar to AMD or CommonJS. However, my Google search for 'Angular.JS make new module' has not yielded any documentation on creating Angular.JS modules. There ...

Detecting URL changes, excluding just the hash, with JavaScript/jQuery

It's interesting to note that some websites are built using a "one-page system". In this type of system, when a user clicks on a link, the site doesn't take them to a new page but instead reloads the existing page with Ajax and updates the URL. ...

Implementing advanced checkbox filtering feature in React

Does anyone have experience with creating dynamic Checkbox filtering in React using Material-UI? I'm finding it challenging because the checkbox options are generated dynamically from incoming data and need to be categorized by type of Select componen ...

Is there a way to automatically submit a form with the logged-in user as the default selection?

Once you complete the sign-up process, you will be directed to the login page. After logging in successfully, you will be redirected to a different page where you can fill out a form with additional information about yourself as a new user. The issue arise ...

I am looking to showcase the JSON output on a ReactJS interface

Here is the output of my JSON data I am using the Map function in ReactJS to display elements from a JSON array. I have attempted the code below and encountered an error stating "Cannot read property '_currentElement' of null." Can someone pleas ...

The validation message from the requiredfieldvalidator is persisting even after filling the textbox with javascript

Is the textbox empty or not when using RequiredFieldValidator? When clicking the submit button, an error message appears but if the textbox is filled using javascript and then clicked elsewhere, the error message does not disappear. However, if something ...

Having trouble loading Bootstrap styles in a dynamically generated table using javascript

I'm currently developing a trivia game that fetches questions from an API. To enhance the look of the game, I decided to utilize Bootstrap. The game itself is constructed as an HTML table using jQuery in JavaScript. However, upon calling the function, ...