Skip to content Skip to sidebar Skip to footer

How To Hide Sidebar When Clicking Outside Of Sidebar?

I have a sidebar that looks like this: Clicking the arrow will collapse the sidebar again. However, I want to auto close the sidebar if I click outside of the sidebar. Would that

Solution 1:

You can do this with code below:

$('body').click(function(event){
   if($(event.target).attr('id') !== "sidebar" && $(event.target).attr('id') !== "sidebarCollapse") {
     $('#sidebar').removeClass('active');
     $('.overlay').removeClass('active');
   }
});

Post a Comment for "How To Hide Sidebar When Clicking Outside Of Sidebar?"