What is the reason behind my phone burger not working and how can I resolve the problem?

I am facing an issue with the burger menu icon on my website. When I click on the burger icon, it doesn't transform into a cross as intended. Even though I can see that the class .active is being added in the DOM, the menu doesn't respond to the click at all. The .img and .nav elements are grid items, so I suspect I may have confused something in the grid container. If you need more details about the project, feel free to ask. I hope the provided information is sufficient to understand the situation. =) Thank you!

$(document).ready(function() {
  $('.header-burger').click(function(event) {
    $('.header-burger, .nav').toggleClass('.active');
  });
});
@media only screen and (max-width: 370px) {
  .nav {
    grid-row: 2;
    grid-column: 1/ span 2;
    position: relative;
    top: -112%;
    width: 100%;
    height: 100%;
    background-color: black;
    padding: 0 0 0 10px;
    z-index: 3;
  }
  .nav .active {
    top: 100%;
  }
  .header-burger {
    display: block;
    position: relative;
    width: 30px;
    height: 20px;
  }
  .header-burger:before,
  .header-burger:after {
    content: '';
    background-color: white;
    position: absolute;
    width: 100%;
    height: 2px;
    left: 0;
  }
  .header-burger:before {
    top: 0;
  }
  .header-burger .active:before {
    transform: rotate(45deg);
    top: 9px;
  }
  .header-burger .active:after {
    transform: rotate(-45deg);
    bottom: 9px;
  }
  .header-burger:after {
    bottom: 0;
  }
  .header-burger span {
    position: absolute;
    background-color: white;
    left: 0;
    width: 100%;
    height: 2px;
    top: 9px;
    transition: all 0.3 ease 0.3;
  }
  .header-burger.active span {
    transform: scale(0);
  }
}
<div class="img">
  <img src="./logo.svg">
  <div class="header-burger"><span></span></div>
</div>

<div class="nav">

  <ul class="burger-ul">
    <li class="burger-li"><a>About</a></li>
    <li class="burger-li"><a>Careers</a></li>
    <li class="burger-li"><a>Events</a></li>
    <li class="burger-li"><a>Products</a></li>
    <li class="burger-li"><a>Support</a></li>
  </ul>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

Answer №1

To apply the active class, you must include the dot. Make sure to remove the dot from your script.

$(document).ready(function() {
  $('.menu-icon').click(function(event) {
    $('.menu-icon, .menu').toggleClass('active');
  });
});

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

Populate a dropdown menu using JSON data

I am working with an SQLite table that has columns for id and name. I have created a JSON array of rows from the autocomplete.php page. Now, I am trying to populate a dropdown list in my select element using this JSON data by utilizing jQuery and JavaScrip ...

Having trouble implementing a nested grid system in Bootstrap

Struggling with creating a grid layout that looks like the one in this image. I initially thought of setting up a row with 2 divided columns, then adding another row+column within each of those 2 columns to place a card inside. This is an excerpt of my c ...

Design a personalized button with a hand-shaped image using CSS

I am aiming to design a unique custom button that resembles the shape of a hand featured in this image, with the intention of adding some functionality to it later. My attempts so far have involved using an SVG path created in GIMP within a button, but all ...

"Utilize PrimeNG's p-tabpanel to bind a unique style class to

When using the tabview component from PrimeNG, I am encountering an issue where I am unable to bind a header style class. Here is my static HTML code that works: <p-tabPanel header="Title" headerStyleClass="badge" formGroupName=&quo ...

How to eliminate the initial class with jQuery

I am encountering some issues with removing a class using jQuery. When I open a modal in Bootstrap, it generates code like this: <div class="modal-backdrop fade in"> in the footer. However, when I open a modal within another modal (2 modals), ther ...

Leveraging Django's JSONResponseMixin for handling AJAX responses

I'm currently using Django in conjunction with AJAX. My goal is to have a javascript file (vote.js) POST data to a Django View, which will then respond with JSON data to be utilized by my javascript's callback function in the HTML. Below is the ...

Failure to load a picture does not trigger onError in the onLoad function

Is there a way to ensure that an image always loads, even if the initial load fails? I have tried using the following code snippet: <img class="small" src="VTVFile4.jpg" onload="this.onload=null; this.src='VTVFile4.jpg?' + new Date();" alt=" ...

What is the method for obtaining the most up-to-date JSON GET request URL?

Using JQGrid with search filters and setting loadOnce=false. I perform a search in the grid and observe the JSON request URL in firebug: http://localhost:8080/myapp/items/listGrid?ticketId=&_search=true&nd=1393573713370&rows=20&page=1& ...

Sending data from jQuery modal to the final input field

In my latest project, I have developed a modal window that features a table with rows of input boxes and buttons: <table class="datatable tablesort selectable paginate full" width="100%"> <tbody> ...

Is there a way for us to determine the time at which the user last took a screenshot or photo?

I am currently developing a website using Django and I have a unique requirement. I need to access the last image that a user has taken on their phone, without the image being shared by anyone else. The photo must be captured by the user's device itse ...

increased space between tables in HTML email design for optimal display in Gmail inbox

Here is the link to my code: http://jsfiddle.net/user1212/G86KE/4/ I am experiencing an issue in Gmail where there is extra white space between 2 tables inside the same cell. I have attempted using display:block; margin:0; padding:0; line-height:0; How ...

Display a pop-up when hovering over a layer with react-leaflet

I am attempting to display a popup when hovering over a layer in react leaflet. Utilizing GeoJson to render all layers on the map and onEachFeature() to trigger the popup on hover, I encountered an issue where the popup only appeared upon click, not hover. ...

Angular text input with customizable placeholder text and embedded icon

Hey there, I'm looking to create a unique custom textbox that includes a text placeholder and a help icon that will display useful information in a popover. https://i.sstatic.net/Zh0IK.png When typing into the input, the textbox should have a specif ...

What is the best way to ensure the proper formatting of my initial form?

Hello, I am encountering some challenges with formatting my form. As a beginner in web coding, I apologize for what may seem like a simple issue - this is the first form I am attempting to code. My objective is as follows: On screens and tablets: have fo ...

Server elements fail to refresh following the use of JQuery AjaxUpload

I have been using JQuery AjaxUpload to upload an image and then attempt to update the image control with the freshly uploaded image. However, my code is not functioning as expected and I am unable to set ViewState. I would like to figure out why this is ha ...

A solution for optimizing accessibility by concealing anchor outlines in Internet Explorer and Firefox

Initially, I want to clarify that I acknowledge the fact that removing outlines impairs keyboard navigation. In contrast to Internet Explorer and Firefox, Google Chrome handles this issue by displaying outlines exclusively when the user interacts with the ...

Display a hidden division when a radio button is selected using Javascript and Jquery

Currently, I am in the process of constructing a form that triggers a series of additional questions based on the selected answer. Below is my current working code snippet: $(".appliedWorked").click(function(){ if($(this).val()==="appliedWorkedYes") ...

The parallax background features a sleek design with crisp white borders framing the edges

We are currently facing an issue while attempting to incorporate a parallax background on our website. The problem lies in an unwanted white border surrounding the image that can be seen at this link: https://i.stack.imgur.com/pt0Pf.jpg. Despite trying va ...

Convert JSON data into HTML format

Can you assist me in creating the HTML DIV block for the response I received in JSON format? Here is the JSON format: [{"REL_NAME" : " 999999999","SO" : "","U_ID" : "105"}] Snippet: function ProcessData(data) { $('#accNo12').empty(); if (d ...

What could be causing the background image on my element to not update?

I'm attempting to utilize a single background image that is 3 pixels wide and 89 pixels tall. Each vertical stripe of 1 pixel will serve as the background for a different div. I had presumed that adjusting the background-position by -1px 0 and specif ...