1

As I do not know js I'm looking for help - I would need this simple jquery code written in pure javascript:

$( document ).ready(function() {
    $(".mobile-menu-cta").click(function() {
          $(".mobile-menu").toggle();
    });
});
  • everything has a direct equivalent in JavaScript except `toggle` – Guerric P Apr 18 '21 at 17:07
  • http://youmightnotneedjquery.com/ Also what did you try, you have to try it yourself first. – ikiK Apr 18 '21 at 17:19
  • Check out my second solution here - https://stackoverflow.com/questions/66520548/toggle-visibility-of-the-current-element/66520631#66520631. This is how you can make a toggle to JavaScript. If you have any problems with the code, then let me know. I will help make a solution. – s.kuznetsov Apr 18 '21 at 17:39

1 Answers1

1

This mimics the toggle behaviour:

document.addEventListener('DOMContentLoaded', function(e) {
  const menuCta = document.querySelector('.mobile-menu-cta');
  const menu = document.querySelector('.mobile-menu');

  menuCta.addEventListener('click', function(e) {
    e.preventDefault();

    if (menu.style.display === 'none') {
      menu.style.display = 'block';
    } else {
      menu.style.display = 'none';
    }
  });
});