I wrote a script that opens the drop-down menu and closes it when you click in any part of the window or when you click on the button that opens it. But the problem is that the drop-down menu is closed by clicking on it, which should not be. How to fix this?
$(function() { $('.dropdown').click(function() { $(this).nextAll('.dropdown-box').toggleClass('active'); }); $(window).click(function CloseDropDown(event) { var target = $(event.target); var dropdowns = $('.dropdown-box'); if(!target.is('.dropdown')) { dropdowns.each(function() { if($(this).hasClass('active')) { $(this).removeClass('active'); } }); } }); });