Issues with navigation on mobile devices

Having trouble getting an icon to show up in the mobile view that can toggle the menu on and off. Currently, my code is not working at all.

I'm struggling with understanding how to use ids and inputs properly here.

If anyone could provide some guidance on what I might be doing wrong, I would greatly appreciate it. Thank you in advance!

//here's what I have so far

<nav class="navMenu">
<input id="menu-icon" type="checkbox">
<label id="menu-icon" class="iconMenuLbl" for="menu-icon"></label>
<ul>

    <li>
        <a href=""><img class="navImg" src="media/Home-tall.png" alt=""></a>
    </li>
    <li>
        <a href="summary"><img class="navImg" src="media/My-Details-tall.png" alt=""></a>
    </li>
    <li>
        <a href="loans"><img class="navImg" src="media/My-Loans-tall.png" alt=""></a>
    </li>
    <li id="loggedin-box" class="">
        <form method="POST" action="login">
        <div>
            <strong>some name</strong>
        </div>
        <button style="padding:0px;" name="logout" type="submit">
        <img class="navImg" src="media/Sign-Out.png">
        </button>
        </form>
    </li>
</ul>
</nav>

//js file

$(function() {
  var menuVisible = false;
  $('#menu-icon').click(function() {
    if (menuVisible) {
      $('.navMenu').css({'display':'none'});
      menuVisible = false;
      return;
    }
    $('.navMenu').css({'display':'block'});
    menuVisible = true;
  });
  $('.navMenu').click(function() {
    $(this).css({'display':'none'});
    menuVisible = false;
  });
});

Answer №1

It appears that there are two identifiers with the same name, 'menu-icon'. In order to comply with coding standards, please rename one of the identifiers to ensure uniqueness. Remember, IDs should always be unique. Additionally, make sure to move your input field outside of the nav tag for proper structure.

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

Is it possible to divide the outcome of an array in an ejs file across multiple pages?

Currently, I am in the process of constructing a blog using nodejs, express, and mongodb. Upon creating an article, it gets stored in a database alongside all other articles. For the website's homepage, I implemented an array with objects to locally s ...

Using the div tag will result in a new line being created

Whenever I try to create an element with a div, I notice there is always some space between the content and the border (blue line). On the other hand, using span causes the content to break, appearing outside the borders. Here is my CSS code: #m ...

Utilize AJAX in JavaScript file

I am encountering an issue with the following code: function inicioConsultar(){ $(function(){ $('#serviciosU').change(function(){ if ($('#serviciosU').val()!= "-1") { $.ajax({ url: "@Url. ...

Retrieve the body's coordinates when dragging an element using the jQuery UI library

How can I obtain the coordinates of a dragged div upon drag and drop action, including left, right, and top positions? Additionally, how do I then use Ajax to post these coordinates? An example link can be found at jsfiddle.net/qPw92 <html> &l ...

Prevent the bootstrap dropdown menu from closing when encountering a login error during form validation using ajax and codeigniter

I encountered an issue with my dropdown menu login that utilizes bootstrap ajax and codeigniter. When I attempt to submit the form and there is an error, I have to click multiple times before the error message appears because the dropdown menu keeps closin ...

Capture the height values from various divs and store them in an array, then utilize these values to adjust the size of other

My goal is to achieve the following: (1) Collect heights from multiple divs and store them in an array. (2) Apply these heights to other elements. The first element should receive the first value, the second element should receive the second value of the ...

What is the best way to retrieve keys and values in jQuery after receiving an object through $.ajax and json_encode($arr) in PHP?

4 In my PHP code: $arr = array( 10=>"ten", 5=>"five", 2=>"two"); return json_encode($arr); When I use JS with $.ajax(): success: function(data){ console.log(data);} 5 After checking the console, it shows : Object {2: "two", 5: "five", 10: " ...

Is it possible to subtract an integer value from an HTML SQL database?

Currently, I am in the process of learning HTML, PHP, and other programming languages. My latest project involves creating a SQL database in phpMyAdmin with names associated with integer values, such as: Nickname 20 Nickname 30 Bank 10, and so on. Now, ...

Obtain an instance of a class within a function that is contained within an instance object in TypeScript/Angular

There is a separate object responsible for managing a specific dialog box in my application. The challenge lies in accessing the instance of the class, even though the functions are self-explanatory. I attempted to use the conventional method of that = thi ...

Styling CSS for circular buttons

I am a newcomer and feeling quite puzzled. When using a div tag with the same width and height along with border-radius: 50%, it always transforms into a circle. However, when attempting to create a circular button using the 'a' tag, it doesn&apo ...

Instructions for executing code after the completion of an .each loop

I've experimented with different methods to achieve this goal. For example, in the code snippet below, I attempted to execute a code after each iteration of .each. function test(){ var iterate = $.each(ohrArray, function(i, val){ var o ...

What steps do I need to take to develop a Django and SvelteKit web application?

While I have experience with Bootstrap and Django, I am new to other frontend frameworks like Angular, React, and SvelteKit. Recently, I decided to give SvelteKit a try but I'm feeling overwhelmed by my lack of familiarity with it. Following the tuto ...

Using Ajax with Angular services

Recently, I decided to explore Angular JS and Async calls as an alternative to $JQuery. However, I encountered a peculiar issue while making ajax calls. To adhere to 'best practices', I shifted my ajax requests to a service and then initiated th ...

What is the best way to exclude certain values from Objects in Javascript?

Imagine having an object structured like this: "errors": { "name": { "name": "ValidatorError", "message": "Minimum length 6 characters.", "propert ...

Ways to delete the content within the span element when the textbox contains text?

Is it possible to dynamically remove the text from a span element based on the content of a textbox using jQuery? I have tried implementing the code below which includes two conditions; if the textbox is empty, display the span text, otherwise remove it. ...

Incorrect port being used for fetching URL in redux.js

I have developed a MERN application that utilizes both async/await with Axios and Redux to handle the data flow within the application. Redux is primarily used for login and authorization, as shown in this tutorial. While some shared tables are fetched thr ...

"Encountered the following error message: "Error [ERR_HTTP_HEADERS_SENT]: Unable to modify headers once they have been sent to the client" while attempting

My attempts to set a cookie when someone inputs the correct key (1234) are resulting in an error message: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client. I'm confused on what steps to take next. I've tried r ...

Using Three.js to display a texture mapping on a specific section of an object

What is the most efficient way to display texture on the center/left/right side of a 2D object? I have experimented with manipulating the offset and repetition of the texture without success, and I have found no answers elsewhere. In addition, I attempte ...

Display search results within the same page using jQuery, without redirecting to a new page

I am currently working on creating a custom search form for an e-commerce platform using Magento. This search form consists of multiple dropdown select boxes. While the form is operating correctly, once the form is submitted with selected search criteria, ...

Comparing the parsing of fetch() JSON response output in Node.js to parsing a JSON variable

Could someone clarify the difference between parsing a Variable JSON object and parsing fetch() response data JSON object stored in a variable? For example: If we have a variable like this: var myJSON = { "items" : [ { "id" : &q ...