lundi 23 mars 2020

I want to create a simple class toggle in jQuery

I am currently working on a website where I am creating a hamburger menu for mobile responsive. I want to be able to toggle the menu on and off. I have done this with toggleClass but it doesn't work all the time.

I want to create an if statement myself but I don't know how this works yet as I'm new at JavaScript. Here is the code I used:

$('#menu-toggle').on('click', function() {
  var element = $(this);
  element.toggleClass("active");
}); 

Aucun commentaire:

Enregistrer un commentaire