Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 3

JavaScript Close on Click

Solved! Go to Solution.

Hi ,
I have this nav-bar https://codepen.io/raul-rogojan/pen/LoOoVm .
I have managed to make it work on outside click with the help of somebody but I would like it to close after I click on About for example and I have no idea how I should do that.
Keep in mind that I an now to coding and JavaScript is my worse nightmare. :D
Thanks !

2 Replies
Solution
Copilot Lvl 2
Message 2 of 3

Re: JavaScript Close on Click

Is this what you meant?

https://codepen.io/libraminh/pen/wbLOBx?editors=0010

 

// Handle close bar
const closeNavbar = () => {
  $('.nav-links').removeClass('nav-activ')
}

// Toggle hamburger animation
const toggleHamburgerBtn = () => {
  $(".burger").toggleClass('animation')
}

// Handle change link
const changeLink = () => {
  $('.nav-links a').on('click', () => {
    closeNavbar()
    toggleHamburgerBtn()
  })
}

 

 

 
 
 
Copilot Lvl 3
Message 3 of 3

Re: JavaScript Close on Click

Yess !! And I understend it too hahah . 

Sorry , I am new to coding and I get excited when I understend stuff :D