Ваш код работает, если вы удалите часть $ (document) .click (). Вам также не нужен protectDefault () (но он также работает, если вы оставите его в коде)
$('.hide-menu').click(function(event) {
$('body').toggleClass('hide-sidebar');
});
.hide-sidebar nav {
display: none;
}
/*
These nav styles are only to highlight the showing nav, they are not needed and can be restyled as wished
*/
nav {
background-color: pink;
border: 1px solid red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button" class="hide-menu"> Hide Menu </button>
<nav>
<a href="#"> link </a>
</nav>