$(document).click(function(event){ if (event.target !== $('#nav')) { $('#nav').removeClass('open'); $('#navIcon').removeClass('fa-times'); $('#navIcon').removeClass('fa-align-left'); }else{ event.stopPropagation(); } }); This code should close the menu if the purpose of the click is not a block with a menu. But if the click on this particular block then the function stops, But after writing it, the menu does not open at all.