Having trouble opening or closing the nav menu with a click?

I've been struggling to get my hamburger menu to work properly for a while now. I've tried various solutions, but it seems like I just can't get it to open (Menu not opening is the issue :( ),

The tutorial I followed to create this menu can be found here -> Youtube Link

If you have any suggestions on how to fix this or if you know of a similar post that could help me out, please let me know. Thank you!

$(document).ready(function() {
  $(".burger-nav").on("click", function() {
    $("header nav ul").toggleClass("open");
  });

});
header nav ul {
  height: 0;
  overflow: hidden;
  background: #6134A3;
}

header nav ul.open {
  height: auto;
}

.burger-nav {
  padding: 0px;
  margin: 0px;
  display: block;
  height: 40px;
  width: 100%;
  cursor: pointer;
  background-image: url(images/nav.png);
  background-repeat: no-repeat;
  background-size: 10%;
  background-position: 97%;
  background-color: #502196;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<head>
  <title>MENU</title>
  <link rel="stylesheet" href="slicknav.css" />
  <script language="JavaScript" type="text/javascript" scr="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>

<style>

</style>

<body>
  <header>
    <div class="wrapper">
      <nav>
        <a class="burger-nav"></a>
        <ul>
          <li><a href="#">item 1</a></li>
          <li><a href="#">item 2</a></li>
          <li><a href="#">item 3</a></li>
          <li><a href="#">item 4</a></li>
        </ul>
      </nav>
    </div>
  </header>
  <!--watch this video to finish drop down https://www.youtube.com/watch?v=FDh7Mdl2oww -->


  <script language="JavaScript" type="text/javascript" scr="menu.js"></script>
</body>

Answer №1

Make sure to always use the most recent version of jQuery...

<head>
  <title>MAIN MENU</title>
  <link rel="stylesheet" href="slicknav.css" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>

Answer №2

One reason for this issue could be the height: auto property being used. Consider setting a specific value such as 400px or 100vh. Alternatively, you can experiment with a solution like the following:

$(document).ready(function() {
    $(".burger-nav").on("click", function() {
          $("header nav ul").slideToggle(400);
    });
});

header nav ul {
  height: auto;
  overflow: hidden;
  display: none;
  background: #6134A3;
}

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

Clicking on a link with an onclick method renders selenium ineffective in producing any action

The specified element is: <a href="#" onclick="submitViaAjax(null, url);return false;">Add</a> After using element.click() to try clicking the link, the onclick method fails to execute. Is there a way to ensure the method is executed success ...

Having trouble reaching an injected dependency beyond the controller method

Can an injected dependency on a controller be accessed outside of it? function clientCreateController(ClientsService, retrieveAddress) { var vm = this; vm.searchCep = searchCep; } function searchCep(cep) { retrieveAddress.find(cep) .success ...

Guide on dynamically displaying a keyboard in an Android mobile application when an input field is present, utilizing jQuery

When accessing the input field in my application on Android mobile devices, I need the keyboard to appear dynamically. I attempted to achieve this using jQuery by using the code $('#appear').focus(); Although the focus is being set on the input ...

Angular causing WKWebview to freeze

Situation Our Angular+Bootstrap app is functioning smoothly in Desktop on all operating systems, as well as Android and iPhone devices. There are no visible JavaScript errors or CSS warnings. Dilemma However, an issue arises intermittently while using t ...

Using React JS to iterate over an array and generate a new div for every 3 items

It's a bit challenging for me to articulate my goal effectively. I have a JSON payload that looks like this: { "user": { "id": 4, "username": "3nematix2", "profile_pic": &qu ...

Monitor checkbox status to trigger confirmation dialog

My goal is to prevent the checkbox from changing if 'NO' is clicked in a dialog. The dialog pops up, but I can't figure out how to wait for it to close before allowing the checkbox change. I've attempted using Promises and doing everyt ...

Is there a way to skip importing React from the test file when using Jest?

I'm currently using testing-library with React Within my test file, I have the following setup: import { render, screen } from '@testing-library/react' import React from 'react' // It would be ideal to avoid including this in each ...

What is the best way to identify a trio of items in an array whose combined total matches a specific target sum?

I am currently utilizing three loops to tackle this problem, but the complexity is O(n3). Is there a way to achieve this with a lower complexity level? Sharing a JS Fiddle code snippet for the three loops approach: var arr = [1, 2, 3, 4, 5, 6, 7, 8]; v ...

Troubleshooting problem with Chrome's getRangeAt function following changes to innerHTML of a contenteditable div using code

Here is an example of my HTML code: <button onclick="testfunction()">test</button> <div id="divT" spellcheck="false" contenteditable="true"></div> This is the JavaScript portion: document.get ...

Material design for Angular applications - Angular Material is

Recently, I decided to explore the world of Angular and its accompanying libraries - angular-material, angular-aria, and angular-animate. I'm eager to experiment with this new styling technique, but it seems like I've hit a roadblock right at the ...

Text overlaps when li element is nested inside another element

Seeking assistance in creating a CSS/HTML menu bar that triggers list elements on hover. Facing difficulty arranging the list in two columns. Code Sample:http://jsfiddle.net/Km922/1/ <!DOCTYPE html> <html lang="en"> <head> <meta ...

The container-fluid class expands to full width of the page, except for the navbar

Hey there, looking for some help with your CSS design? Let's take a look at your code snippet: .container-fluid-1 { padding: 0; } .navbar { ...

Ajax Loading Bar similar to YouTube is not functioning as expected

I've implemented the YouTube-like Ajax Loading Bar to load a PHP file. Here is the JavaScript code I'm using: $(".ajax-call").loadingbar({ target: "#loadingbar-frame", replaceURL: false, direction: "right", async: true, complete: fun ...

Enhancing the visual appeal of a JSON object with texture using Three.js

Struggling to apply texture to my 3D Dog JSON model exported from clara.io. Tried using Objectloader and Textureloader, but the texture won't load onto the model. The code might be incorrect or in the wrong place. Looked at other examples but no luck ...

An issue arises when data from the parent ajax call is being referenced

I am encountering a situation where I have nested ajax functions within each other. $.ajax({ url: '../...', type: 'POST', dataType: 'JSON', ...

Incorporating invisible surprises into a fixed menu that reveal themselves as you scroll

I am working on implementing a top navigation and a sticky sub-navigation feature. The goal is to have the sticky nav become the top nav when the user scrolls down the page, similar to the functionality on this website - The issue I'm facing is with ...

What is the best way to save an object as a value for a radio input in Vue?

Looking to store values from an array of objects into radio inputs in Vue.js? Here's what I have: const plans = [{type:'2'},{type:'3'},{type:'1'}] I attempted the following approach: <input type="radio" v-mo ...

Ways to adjust the select element to match the width of its current option

As I work on building a form, I'm looking for a way to make the select element adjust its width based on the length of its current option. Essentially, I want the select element to expand or contract depending on the width of its longest option. I&ap ...

Merging an assortment of items based on specific criteria

I have the following TypeScript code snippet: interface Stop { code: string } interface FareZone { name: string; stops: Stop[]; } const outbound: FareZone[] = [{name: 'Zone A', stops: [{ code: 'C00'}] }, {name: 'Zone B ...

What is the best way to eliminate unwanted white space at the top of the page?

I'm new to web development and I'm exploring the concept of white space at the top of a webpage. Here is a snippet of my code: HTML: <div> <p>lorem ipsum</P> </div> CSS: div { background-color: black; } I attem ...