Skip to content

Instantly share code, notes, and snippets.

@raphaelgoetter
Last active February 4, 2024 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raphaelgoetter/cdb5f61f4477e02baca238c888ca35f5 to your computer and use it in GitHub Desktop.
Save raphaelgoetter/cdb5f61f4477e02baca238c888ca35f5 to your computer and use it in GitHub Desktop.
JS nav
(function () {
function toggleNav() {
// Define targets
const button = document.querySelector('.burger-button');
const target = document.querySelector('#navigation');
button.addEventListener('click', () => {
const currentState = target.getAttribute("data-state");
if (!currentState || currentState === "closed") {
target.setAttribute("data-state", "opened");
button.setAttribute("data-expanded", "true");
} else {
target.setAttribute("data-state", "closed");
button.setAttribute("data-expanded", "false");
}
});
} // end toggleNav()
toggleNav();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment