There is a script that, when you hover over a menu item, should change the class of a block with subcategories.

$('.js-menu-trigger').hover(function () { if(!$(this).hasClass('sub--null')) { $('.js-menu-screen').toggleClass('is-visible'); $(this).toggleClass('sub--visible'); } }); 

The problem is that if you hover over a menu item before the page loads, the script sets the class for the item, which is stored in html. And because of this, a block is displayed, which should be visible only when you hover over an element

  • How to put it on the menu before the page loads? How will you get it if the page hasn't loaded yet? - Yuri
  • @Yuri, at the moment when the html & CSS part appeared, but the scripts and so on are being uploaded. - E_K

1 answer 1

But what if you use both hover functions to indicate specifically that there is a class when you hover, there is no class during the assignment?

 $('.js-menu-trigger.sub--null').hover(function () { $('.js-menu-screen').addClass('is-visible'); $(this).addClass('sub--visible'); },function () { $('.js-menu-screen').removeClass('is-visible'); $(this).removeClass('sub--visible'); } });