$( ".has-submenu" ).click(function() { if ($(this).find(".sub-menu").is(":hidden")){ $(this).addClass('open'); }else { $(this).removeClass('open'); } $(this).find(".sub-menu").slideToggle(); });
Add / remove parent class when child is visible hidden
The removeClass() removes classes to the selected elements while the addClass() adds them.