Issue with menu display after clicking icon

On my website, I am trying to set up an icon that will display a menu bar for mobile users. I have written some JavaScript code for this functionality, but it's not working as expected. My approach involved creating an element called "Menu" and assigning the icon button class to it. However, when I tried toggling a simple classlist for the div I wanted to appear, the class "hamburgermenu" showed up within the button class instead of on its own. Can anyone help me identify what might be causing this issue and guide me in the right direction?

Here's the code snippet:

const menu = document.querySelector(".hamburger button"); // Get dropdown menu when clicking on hamburger Icon

menu.addEventListener("click", function() {
    Showdropdown();
});
 
// Showing dropdown content

function Showdropdown() {
  menu.classList.toggle("hamburgermenu");
}
/* General styling attributes */ 
html {
    -webkit-text-size-adjust: 100%;
}

* {
    margin:0;
    padding:0;
    border:0;
    outline:0;
    text-decoration:none;
    list-style:none;
    box-sizing: border-box;
}... (remaining CSS follows)
<!DOCTYPE html> 
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>DraftFlex</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1">
        <link rel="stylesheet" href="styles.css">... (rest of HTML content provided below)
            </ul>
          </nav>
        </header>
      <main>  

      </main>
    </body>
</html>

Answer №1

`.hamburgermenu {
    display:block;
    width:10rem;
    height:10rem;
    background-color:rgb(255 255 255);
    margin-top: 15rem;
    border-radius:5rem;
}

Ensure there are no redundant classes in your CSS like the duplicate .hamburgermenu with display: none; property. It's important to avoid duplicates for cleaner and more efficient 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

Arrange the selection options by price using jQuery

Sorting options by price is my goal, but despite trying various codes, I have not been successful! This is the original structure: <select id="product-list"> <option>product 1- [2$]</option> <option>product 2- [4$]< ...

After refreshing the page, the ngRoute white page is displayed

I've encountered an issue with my Angular website. I built it using ngRoute, but when I click on a link, a white page appears. Only after refreshing the page does the content actually show up. Even in the browser's DevTools, you can see the html ...

Utilizing the power of combined variables in Javascript

Is there a method to incorporate variables in each loop of a javascript loop? For instance, if I were to insert this code into a loop if (e1) {item_text += '{id:"' + id[1] + '",lvl:' + e1lvl + '},<wbr>'} if (e2) {item_ ...

The Bootstrap navbar is not aligning correctly and the collapse feature is not functioning properly

My first experience with Bootstrap is not going as expected. I am trying to create a navigation bar where the links align to the right, and when the screen size decreases, it changes to a hamburger menu on the right side. However, the links do not move to ...

Adjust the parent container to perfectly accommodate the child element

Is there a way to resize the container box to fit its dynamic content without using JavaScript? Here is the sample code for the problem: <div id="container"> <div id="content"></div> </div> #container { position: relativ ...

Transitioning to TypeScript: Why won't my function get identified?

I am in the process of transitioning a functional JavaScript project to TypeScript. The project incorporates nightwatch.js Below is my primary test class: declare function require(path: string): any; import * as dotenv from "dotenv"; import signinPage = ...

What makes Firefox so much speedier than Chrome when it comes to loading hefty documents?

Currently, I am facing an issue with slow loading times for custom HTML build reports on Google Chrome. It takes a significantly longer time to load compared to Firefox. Approximately 5 seconds on Firefox versus 110 seconds on Google Chrome (measured usi ...

Tips for aligning navigation bar items to the right side

Seeking help with positioning the logo on the left and navigation items on the right using Bootstrap classes, while maintaining responsiveness. Click here for sample image 1 Check out the navbar layout <!-- Logo --> <a class="nav ...

Chrome causing footer problem in Prestashop theme

My footer is not displaying properly on Chrome, but it looks fine on other browsers. I am using a paid theme on my PrestaShop installation, and the support team claims it's an issue with a module, but I'm not convinced. You can visit the website ...

Transferring information from one website to another

I need to transfer content from one website to another while maintaining good SEO practices. Using Iframes is not an option, and PHP won't work in the CMS I'm using. I attempted a different approach: $('#target-div').load('http:/ ...

Exploring the Functionality of Drag and Drop with JPG and GIF in Internet Explorer 9/10/11

When trying to drag, drop, or select a file using a form in Internet Explorer 9/10/11, only JPEG and PNG files are accepted, while JPG and GIF extensions are rejected. This issue is present in both the code I am using below and in the demo found at https:/ ...

Using JavaScript, learn how to extract query parameters and encoded information from a URI

I am looking for a specific module in order to extract information from query parameters within a URL. The format includes 2 query parameters and an encoded piece of data. Do I need to use split functions or is there a more direct approach available? Sampl ...

Unable to adjust table, row, and cell heights in Outlook template due to HTML/CSS formatting issues

I'm struggling to make the height of the leftmost (commented) nested table adjust automatically based on the content in the right section. It displays correctly in Chrome, but does not stretch in Word/Outlook. Any ideas on how to fix this for Word/Ou ...

An intuitive guide on showcasing the dynamically generated variables' values with AngularJS

I am facing an issue with my HTML template code: <p>{{"fieldname_"+lang}}</p> Within the controller, I have defined the following: $scope.lang = "mr"; $scope.fieldname_mr = "Dynamic variable"; My expected result is Dynamic variable, however ...

Assign a value to a text input using React

Whenever the closeEmail function is triggered or called, I need to set the email.emailAddress as the value of the textfield. I'm fairly new to React, what is the syntax or method to achieve this? Any suggestions? #code snippet <div style={{ disp ...

The input value remains unaffected by Bootstrap checkbox and radio button selections

On the Bootstrap JavaScript page, there are examples of using buttons to style checkboxes and radio fields. For instance, a checkbox might be written as: <div class="btn-group" data-toggle="buttons"> <label class="btn btn-primary"> <i ...

Searching for Node.js tutorials using Google API on YouTube

I'm attempting to utilize the Google APIs in Node for a YouTube search. Currently, I'm following a tutorial found here: https://github.com/google/google-api-nodejs-client/#google-apis-nodejs-client I've managed to get some basic functiona ...

Ensuring consistent height for CSS divs and buttons

Is there a way to ensure that my buttons have the same height as the questlist_item? Even after applying the same CSS height:auto;, the heights remain unequal. Any suggestions on how to achieve equal button heights? Thank you! var questlist = [{...}]; ...

Text Separation Within a Singular JSON Object

Currently, I am offering my assistance as a volunteer to develop a fast AngularJS App for a non-profit organization. Although I have successfully set up Angular, the main issue I am encountering has to do with parsing JSON data. The JSON object that I am ...

Struggling with loading react storybook

I am having trouble getting my storybook app to start. It is stuck in a loading state with no errors showing in the console. Can anyone help me figure out what I am doing wrong? Check out the screenshot here storybook/main.js const path = require(' ...