How to auto-close a responsive nav bar?

Hi guys !

I followed a tutorial to make a responsive navigation menu on my website ( my curriculum vitae )
Actually this menu can be close only by clicking on the “hamburger div” but I want this menu to automatically close when users click on the links or click out of the menu.

I suppose I need a condition to say something like " IF users clicked on a link or out ouf the menu SO toggle-of the menu "

If anyone can explain me what I have to do it would be awesome ! I don’t have the level in Js to know what to do :sweat_smile:

My HTML :

  • 1 Nav section containing a UL (class = “nav-links”)
    with few links like the classics “about” “contact”…

  • 1 Div (class =" burger") that contain 3 child as the 3 burger’s lines.

Here is the JavaScript :

const navSlide = () => {
const burger = document.querySelector(’.burger’);
const nav = document.querySelector(’.nav-links’);
const navLinks = document.querySelectorAll(’.nav-links li’);

burger.addEventListener('click', () => { 
    **// Toggle Nav Bar** 
    nav.classList.toggle('nav-active');

    **//Animate Links**
    navLinks.forEach((link, index) => {
        if(link.style.animation){
            link.style.animation = ''
        }else {
            link.style.animation = `navLinkFade 0.5s ease forwards ${index / 7 + 0.3}s`;
        }
    });

    **// Burger animation**
    burger.classList.toggle('_toggle');
});

}
navSlide();


If you need more infos just ask,
thanks you !