jQuery menu for Avascript

Asked

Viewed 35 times

1

I need to create a toogle on the menu at media query, but I want it in pure Javascript, because I’m trying not to use jQuery.

$(document).ready(function(){
      $('.menu').click(function(){
         $('nav').toggleClass('active'); 
      })
    });

How to convert this to jQuery for pure JS?

  • Hello, I’m trying to find the right way to apply, I need to activate a hidden CSS class inside an HTML tag only I’ve tried with Toogle and it wasn’t, I really want to learn the concept in JS. I’m trying to apply for study purposes.

1 answer

1

Converting your code to pure JS would look something like this:

(function() {

      const menu = document.querySelector('.menu');
      const nav = document.querySelector('.nav');

      menu.addEventListener('click', function(){
        this.nav.classList.toggle('active');
      });
})();
  • Thank you, I’ll try to apply here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.