This is more of a note to myself since I keep forgetting and "rediscovering" this technique every time I need it, but if it helps you, great!
The JavaScript way is to toggle displaying the menu based on a button click. For instance, here's an example in Svelte:
[This interactive/preview is only available on the website.]<script lang="ts">
let showMenu = $state(false);
</script>
<button onclick={() => (showMenu = !showMenu)}>
{#if showMenu}
Hide menu
{:else}
Show menu
{/if}
</button>
<nav